Example #1
0
/**
 * TC-Set/Get Attributes test
 * with symlinks
 */
TYPED_TEST_P(TcTest, AttrsTestSymlinks)
{
	const char *PATHS[] = { "AttrsTestSymlinks-Linked1.txt",
				"AttrsTestSymlinks-Linked2.txt",
				"AttrsTestSymlinks-Linked3.txt" };
	const char *LPATHS[] = { "AttrsTestSymlinks-Link1.txt",
				 "AttrsTestSymlinks-Link2.txt",
				 "AttrsTestSymlinks-Link3.txt" };
	tc_res res = { 0 };
	struct tc_iovec iov;
	int i;
	const int count = 3;
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(count, sizeof(tc_attrs));

	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	Removev(PATHS, count);
	Removev(LPATHS, count);

	EXPECT_OK(tc_symlinkv(PATHS, LPATHS, count, false));

	for (i = 0; i < count; ++i) {
		tc_iov4creation(&iov, PATHS[i], 100, getRandomBytes(100));
		EXPECT_NOTNULL(iov.data);
		EXPECT_OK(tc_writev(&iov, 1, false));

		attrs1[i].file = tc_file_from_path(LPATHS[i]);
		tc_attrs_set_mode(&attrs1[i], S_IRUSR);
		tc_attrs_set_atime(&attrs1[i], totimespec(time(NULL), 0));
		attrs2[i] = attrs1[i];
	}

	EXPECT_OK(tc_setattrsv(attrs1, count, false));
	EXPECT_OK(tc_getattrsv(attrs2, count, false));
	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	tc_attrs_set_mode(&attrs1[0], S_IRUSR | S_IRGRP);
	EXPECT_OK(tc_setattrsv(attrs1, count, false));
	EXPECT_OK(tc_lgetattrsv(attrs2, count, false));

	EXPECT_FALSE(S_IROTH & attrs1[0].mode);
	EXPECT_TRUE(S_IROTH & attrs2[0].mode);
	EXPECT_FALSE(compare_attrs(attrs1, attrs2, count));

	EXPECT_OK(tc_getattrsv(attrs2, count, false));
	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	free(attrs1);
	free(attrs2);
}
Example #2
0
/**
 * List Directory Contents Test
 */
TYPED_TEST_P(TcTest, ListDirContents)
{
	const char *DIR_PATH = "TcTest-ListDir";
	tc_attrs *contents;
	int count = 0;

	EXPECT_OK(tc_ensure_dir(DIR_PATH, 0755, 0));
	tc_touch("TcTest-ListDir/file1.txt", 1);
	tc_touch("TcTest-ListDir/file2.txt", 2);
	tc_touch("TcTest-ListDir/file3.txt", 3);

	EXPECT_OK(tc_listdir(DIR_PATH, TC_ATTRS_MASK_ALL, 3, false, &contents,
			     &count));
	EXPECT_EQ(3, count);
	qsort(contents, count, sizeof(*contents), tc_cmp_attrs_by_name);

	tc_attrs *read_attrs = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	read_attrs[0].file = tc_file_from_path("TcTest-ListDir/file1.txt");
	read_attrs[1].file = tc_file_from_path("TcTest-ListDir/file2.txt");
	read_attrs[2].file = tc_file_from_path("TcTest-ListDir/file3.txt");
	read_attrs[0].masks = read_attrs[1].masks = read_attrs[2].masks =
	    TC_ATTRS_MASK_ALL;
	EXPECT_OK(tc_getattrsv(read_attrs, count, false));

	EXPECT_TRUE(compare_attrs(contents, read_attrs, count));

	tc_free_attrs(contents, count, true);
	free(read_attrs);
}
Example #3
0
/**
 * TC-Set/Get Attributes test
 * using File Path
 */
TYPED_TEST_P(TcTest, AttrsTestPath)
{
	const char *PATH[] = { "WritevCanCreateFiles1.txt",
			       "WritevCanCreateFiles2.txt",
			       "WritevCanCreateFiles3.txt" };
	tc_res res = { 0 };
	int i;
	const int count = 3;
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(count, sizeof(tc_attrs));

	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	for (i = 0; i < count; ++i) {
		attrs1[i].file = tc_file_from_path(PATH[i]);
		attrs2[i].file = attrs1[i].file;
	}

	attrs1 = set_tc_attrs(attrs1, count);
	EXPECT_OK(tc_setattrsv(attrs1, count, false));

	for (i = 0; i < count; ++i) {
		attrs2[i].masks = attrs1[i].masks;
	}
	EXPECT_OK(tc_getattrsv(attrs2, count, false));

	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	free(attrs1);
	free(attrs2);
}
Example #4
0
/*
 * Set attributes of many files.
 */
TYPED_TEST_P(TcTest, SetAttrsOfManyFiles)
{
	const int N = 32;
	const char *PATHS[N];

	for (int i = 0; i < N; ++i) {
		char *p = (char *)malloc(64);
		snprintf(p, 64, "SetAttrsOfFile-%03d", i);
		PATHS[i] = p;
	}
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(N, sizeof(struct tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(N, sizeof(struct tc_attrs));
	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	tc_file *tcfs = tc_openv_simple(PATHS, N, O_RDWR | O_CREAT, 0);
	EXPECT_NOTNULL(tcfs);

	for (int i = 0; i < N; ++i) {
		attrs2[i].file = attrs1[i].file = tcfs[i];
	}

	set_tc_attrs(attrs1, N);
	EXPECT_OK(tc_setattrsv(attrs1, N, false));

	for (int i = 0; i < N; ++i) {
		attrs2[i].masks = attrs1[i].masks;
	}
	EXPECT_OK(tc_getattrsv(attrs2, N, false));

	EXPECT_TRUE(compare_attrs(attrs1, attrs2, N));

	tc_closev(tcfs, N);

	for (int i = 0; i < N; ++i) {
		free((void *)PATHS[i]);
	}
	free(attrs1);
	free(attrs2);
}
Example #5
0
/*
 * TC-Set/Get Attributes test
 * using File Descriptor
 */
TYPED_TEST_P(TcTest, AttrsTestFileDesc)
{
	const char *PATHS[] = { "WritevCanCreateFiles4.txt",
			       "WritevCanCreateFiles5.txt",
			       "WritevCanCreateFiles6.txt" };
	int i = 0;
	const int count = 3;
	tc_file *tcfs;
	struct tc_attrs *attrs1 = (tc_attrs *)calloc(count, sizeof(tc_attrs));
	struct tc_attrs *attrs2 = (tc_attrs *)calloc(count, sizeof(tc_attrs));

	EXPECT_NOTNULL(attrs1);
	EXPECT_NOTNULL(attrs2);

	Removev(PATHS, count);
	tcfs = tc_openv_simple(PATHS, count, O_RDWR | O_CREAT, 0);
	EXPECT_NOTNULL(tcfs);

	for (int i = 0; i < count; ++i) {
		attrs2[i].file = attrs1[i].file = tcfs[i];
	}

	set_tc_attrs(attrs1, count);
	EXPECT_OK(tc_setattrsv(attrs1, count, false));

	for (i = 0; i < count; ++i) {
		attrs2[i].masks = attrs1[i].masks;
	}
	EXPECT_OK(tc_getattrsv(attrs2, count, false));

	EXPECT_TRUE(compare_attrs(attrs1, attrs2, count));

	tc_closev(tcfs, count);

	free(attrs1);
	free(attrs2);
}
Example #6
0
int
diff_objs(Tcl_Interp *interp, const char *db1, const char *db2)
{
    struct directory *dp1, *dp2;
    char *argv[4] = {NULL, NULL, NULL, NULL};
    struct bu_vls s1_tcl = BU_VLS_INIT_ZERO;
    struct bu_vls s2_tcl = BU_VLS_INIT_ZERO;
    struct bu_vls vls = BU_VLS_INIT_ZERO;
    int has_diff = 0;

    /* look at all objects in this database */
    FOR_ALL_DIRECTORY_START(dp1, dbip1) {
	char *str1, *str2;
	Tcl_Obj *obj1, *obj2;

	/* check if this object exists in the other database */
	if ((dp2 = db_lookup(dbip2, dp1->d_namep, 0)) == RT_DIR_NULL) {
	    kill_obj(dp1->d_namep);
	    continue;
	}

	/* skip the _GLOBAL object */
	if (dp1->d_major_type == DB5_MAJORTYPE_ATTRIBUTE_ONLY)
	    continue;

	/* try to get the TCL version of this object */
	bu_vls_trunc(&vls, 0);
	bu_vls_printf(&vls, "%s get %s", db1, dp1->d_namep);
	if (Tcl_Eval(interp, bu_vls_addr(&vls)) != TCL_OK) {
	    /* cannot get TCL version, use bu_external */
	    Tcl_ResetResult(interp);
	    has_diff += compare_external(dp1, dp2);
	    continue;
	}

	obj1 = Tcl_NewListObj(0, NULL);
	Tcl_AppendObjToObj(obj1, Tcl_GetObjResult(interp));

	bu_vls_trunc(&s1_tcl, 0);
	bu_vls_trunc(&s2_tcl, 0);

	bu_vls_strcpy(&s1_tcl, Tcl_GetStringResult(interp));
	str1 = bu_vls_addr(&s1_tcl);
	Tcl_ResetResult(interp);

	/* try to get TCL version of object from the other database */
	bu_vls_trunc(&vls, 0);
	bu_vls_printf(&vls, "%s get %s", db2, dp1->d_namep);
	if (Tcl_Eval(interp, bu_vls_addr(&vls)) != TCL_OK) {
	    Tcl_ResetResult(interp);

	    /* cannot get it, they MUST be different */
	    if (mode == HUMAN)
		printf("Replace %s with the same object from %s\n",
		       dp1->d_namep, dbip2->dbi_filename);
	    else
		printf("kill %s\n# IMPORT %s from %s\n",
		       dp1->d_namep, dp2->d_namep, dbip2->dbi_filename);
	    continue;
	}

	obj2 = Tcl_NewListObj(0, NULL);
	Tcl_AppendObjToObj(obj2, Tcl_GetObjResult(interp));

	bu_vls_strcpy(&s2_tcl, Tcl_GetStringResult(interp));
	str2 = bu_vls_addr(&s2_tcl);
	Tcl_ResetResult(interp);

	/* got TCL versions of both */
	if ((dp1->d_flags & RT_DIR_SOLID) && (dp2->d_flags & RT_DIR_SOLID)) {
	    /* both are solids */
	    has_diff += compare_tcl_solids(str1, obj1, dp1, str2, obj2);
	    if (pre_5_vers != 2) {
		has_diff += compare_attrs(dp1, dp2);
	    }
	    continue;
	}

	if ((dp1->d_flags & RT_DIR_COMB) && (dp2->d_flags & RT_DIR_COMB)) {
	    /* both are combinations */
	    has_diff += compare_tcl_combs(obj1, dp1, obj2);
	    if (pre_5_vers != 2) {
		has_diff += compare_attrs(dp1, dp2);
	    }
	    continue;
	}

	/* the two objects are different types */
	if (!BU_STR_EQUAL(str1, str2)) {
	    has_diff += 1;
	    if (mode == HUMAN)
		printf("%s:\n\twas: %s\n\tis now: %s\n\n",
		       dp1->d_namep, str1, str2);
	    else
		printf("kill %s\ndb put %s %s\n",
		       dp1->d_namep, dp2->d_namep, str2);
	}
    } FOR_ALL_DIRECTORY_END;