/*-1* Copyright (c) 2014 Baptiste Daroussin <[email protected]>2* All rights reserved.3*~4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer9* in this position and unchanged.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*~14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <atf-c.h>27#include <sys/types.h>28#include <private/utils.h>2930ATF_TC_WITHOUT_HEAD(merge);3132ATF_TC_BODY(merge, tc)33{34xstring *b;35b = xstring_new();36char *pivot = "test1\ntest2\n";37char *modified = "test1\n#test2\n";38char *new = "test1\ntest2\ntest3\n";3940ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);41fflush(b->fp);42ATF_REQUIRE_STREQ(b->buf, "test1\n#test2\ntest3\n");4344xstring_reset(b);45pivot = "test1\ntest2";46modified = "test1\n#test2";47new = "test1\ntest2\ntest3";4849ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);50fflush(b->fp);51ATF_REQUIRE_STREQ(b->buf, "test1\n#test2test3");5253xstring_reset(b);54pivot = "test1\ntest2";55modified = "test1\n";56new = "test1\ntest2\ntest3";5758ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);59fflush(b->fp);60ATF_REQUIRE_STREQ(b->buf, "test1\ntest3");6162xstring_reset(b);63pivot = "test1\ntest2\ntest3";64modified = "test1\na\ntest2\ntest3";65new = "test1\ntest2\ntest3";6667ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);68fflush(b->fp);69ATF_REQUIRE_STREQ(b->buf, "test1\na\ntest2\ntest3");7071xstring_free(b);72}7374ATF_TP_ADD_TCS(tp)75{76ATF_TP_ADD_TC(tp, merge);7778return (atf_no_error());79}808182