From: Eric Bollengier Date: Thu, 24 Mar 2022 14:59:37 +0000 (+0100) Subject: Add unittests xattr_append_test.c X-Git-Tag: Release-11.3.2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df58321934299263b3d33aed2ae07339ead1e599;p=thirdparty%2Fbacula.git Add unittests xattr_append_test.c --- diff --git a/bacula/src/tools/xattr_append_test.c b/bacula/src/tools/xattr_append_test.c new file mode 100644 index 000000000..f4d80224c --- /dev/null +++ b/bacula/src/tools/xattr_append_test.c @@ -0,0 +1,75 @@ +/* + Bacula(R) - The Network Backup Solution + + Copyright (C) 2000-2022 Kern Sibbald + + The original author of Bacula is Kern Sibbald, with contributions + from many others, a complete list can be found in the file AUTHORS. + + You may use this file and others of this release according to the + license defined in the LICENSE file, which includes the Affero General + Public License, v3.0 ("AGPLv3") and some additional permissions and + terms pursuant to its AGPLv3 Section 7. + + This notice must be preserved when any source code is + conveyed and/or propagated. + + Bacula(R) is a registered trademark of Kern Sibbald. +*/ + +#include "bacula.h" +#include "../lib/unittests.h" + +#define CIFS_XATTR "system.cifs_acl" +#define CIFS_XATTR_LEN 15 + + +int main(int argc, char **argv) +{ + Unittests u("t"); + POOL_MEM q; + int l, l2; + char buf[512]; + + Mmsg(q, "test1"); + l = strlen(q.c_str()); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l2 == (l+CIFS_XATTR_LEN+1), "Check add string"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + l = xattr_list_append(q.addr(), l2, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l == l2, "Check string already in (last pos)"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l, buf, sizeof(buf))); + + l = 5 + 1 + CIFS_XATTR_LEN + 1; + memcpy(q.c_str(), "test1\0" CIFS_XATTR, l); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l == l2, "Check string already in (last pos)"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + l = 5 + 1 + 5 + 1; + memcpy(q.c_str(), "test1\0test2\0", l); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok((l + CIFS_XATTR_LEN + 1) == l2, "Check string added"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + l = 5 + 1 + 5 + 1 + CIFS_XATTR_LEN + 1; + memcpy(q.c_str(), "test1\0test2\0" CIFS_XATTR, l); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l == l2, "Check string already in (3rd)"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + l = 5 + 1 + 5 + 1 + CIFS_XATTR_LEN + 1 + 5 + 1; + memcpy(q.c_str(), "test1\0test2\0" CIFS_XATTR "\0test3\0", l); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l == l2, "Check string already in (3rd)"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + Mmsg(q, ""); + l = strlen(q.c_str()); + l2 = xattr_list_append(q.addr(), l, CIFS_XATTR, CIFS_XATTR_LEN); + ok(l2 == (l+CIFS_XATTR_LEN+1), "Check add string (empty)"); + Dmsg1(0, "%s\n", asciidump(q.c_str(), l2, buf, sizeof(buf))); + + return report(); +}