Skip to content

Commit

Permalink
Fix group cpp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatia committed Oct 9, 2024
1 parent 02e3d3f commit 1e7e70e
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 40 deletions.
18 changes: 9 additions & 9 deletions test/src/unit-capi-group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ TEST_CASE_METHOD(
rc = tiledb_group_open(ctx_, group2, TILEDB_WRITE);
REQUIRE(rc == TILEDB_OK);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
rc = tiledb_group_add_member_with_type(
ctx_, group1, array1_uri.c_str(), false, nullptr, TILEDB_ARRAY);
REQUIRE(rc == TILEDB_OK);
Expand Down Expand Up @@ -736,8 +736,8 @@ TEST_CASE_METHOD(
rc = tiledb_group_open(ctx_, group1, TILEDB_WRITE);
REQUIRE(rc == TILEDB_OK);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
rc = tiledb_group_add_member_with_type(
ctx_, group1, array1_uri.c_str(), false, "one", TILEDB_ARRAY);
REQUIRE(rc == TILEDB_OK);
Expand Down Expand Up @@ -779,7 +779,7 @@ TEST_CASE_METHOD(
rc = tiledb_group_remove_member(ctx_, group1, "one");
REQUIRE(rc == TILEDB_OK);
// Add one back with different URI
if (add_by_type) {
if (add_with_type) {
rc = tiledb_group_add_member_with_type(
ctx_, group1, array2_uri.c_str(), false, "one", TILEDB_ARRAY);
REQUIRE(rc == TILEDB_OK);
Expand Down Expand Up @@ -858,8 +858,8 @@ TEST_CASE_METHOD(
rc = tiledb_group_open(ctx_, group2, TILEDB_WRITE);
REQUIRE(rc == TILEDB_OK);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
rc = tiledb_group_add_member_with_type(
ctx_, group1, array1_uri.c_str(), false, "one", TILEDB_ARRAY);
REQUIRE(rc == TILEDB_OK);
Expand Down Expand Up @@ -1236,8 +1236,8 @@ TEST_CASE_METHOD(
rc = tiledb_group_open(ctx_, group2, TILEDB_WRITE);
REQUIRE(rc == TILEDB_OK);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
rc = tiledb_group_add_member_with_type(
ctx_, group1, array1_relative_uri.c_str(), true, nullptr, TILEDB_ARRAY);
REQUIRE(rc == TILEDB_OK);
Expand Down
122 changes: 91 additions & 31 deletions test/src/unit-cppapi-group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,26 @@ TEST_CASE_METHOD(

// Set expected
std::vector<tiledb::Object> group1_expected = {
tiledb::Object(tiledb::Object::Type::Array, array1_uri, "array1"),
tiledb::Object(tiledb::Object::Type::Array, array2_uri, "array2"),
tiledb::Object(tiledb::Object::Type::Group, group2_uri, "group2"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array1_uri),
"array1"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
"array2"),
tiledb::Object(
tiledb::Object::Type::Group,
vfs_test_setup_.with_prefix(group2_uri),
"group2"),
};
std::vector<tiledb::Object> group2_expected = {
tiledb::Object(tiledb::Object::Type::Array, array3_uri, "array3"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array3_uri),
"array3"),
};
std::cerr << group1_expected[0].uri() << std::endl;

tiledb::Group group1(ctx_, group1_uri, TILEDB_WRITE);
group1.close();
Expand All @@ -316,8 +329,8 @@ TEST_CASE_METHOD(
set_group_timestamp(&group2, 1);
group2.open(TILEDB_WRITE);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
group1.add_member(array1_uri, false, "array1", TILEDB_ARRAY);
group1.add_member(array2_uri, false, "array2", TILEDB_ARRAY);
group1.add_member(group2_uri, false, "group2", TILEDB_GROUP);
Expand Down Expand Up @@ -414,12 +427,24 @@ TEST_CASE_METHOD(

// Set expected
std::vector<tiledb::Object> group1_expected = {
tiledb::Object(tiledb::Object::Type::Array, array1_uri, std::nullopt),
tiledb::Object(tiledb::Object::Type::Array, array2_uri, std::nullopt),
tiledb::Object(tiledb::Object::Type::Group, group2_uri, std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array1_uri),
std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
std::nullopt),
tiledb::Object(
tiledb::Object::Type::Group,
vfs_test_setup_.with_prefix(group2_uri),
std::nullopt),
};
std::vector<tiledb::Object> group2_expected = {
tiledb::Object(tiledb::Object::Type::Array, array3_uri, std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array3_uri),
std::nullopt),
};

tiledb::Group group1(ctx_, group1_uri, TILEDB_WRITE);
Expand All @@ -432,8 +457,8 @@ TEST_CASE_METHOD(
set_group_timestamp(&group2, 1);
group2.open(TILEDB_WRITE);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
group1.add_member(array1_uri, false, std::nullopt, TILEDB_ARRAY);
group1.add_member(array2_uri, false, std::nullopt, TILEDB_ARRAY);
group1.add_member(group2_uri, false, std::nullopt, TILEDB_GROUP);
Expand Down Expand Up @@ -541,12 +566,24 @@ TEST_CASE_METHOD(

// Set expected
std::vector<tiledb::Object> group1_expected = {
tiledb::Object(tiledb::Object::Type::Array, array1_uri, std::nullopt),
tiledb::Object(tiledb::Object::Type::Array, array2_uri, std::nullopt),
tiledb::Object(tiledb::Object::Type::Group, group2_uri, std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array1_uri),
std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
std::nullopt),
tiledb::Object(
tiledb::Object::Type::Group,
vfs_test_setup_.with_prefix(group2_uri),
std::nullopt),
};
std::vector<tiledb::Object> group2_expected = {
tiledb::Object(tiledb::Object::Type::Array, array3_uri, std::nullopt),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array3_uri),
std::nullopt),
};

tiledb::Group group1(ctx_, group1_uri, TILEDB_WRITE);
Expand All @@ -559,8 +596,8 @@ TEST_CASE_METHOD(
set_group_timestamp(&group2, 1);
group2.open(TILEDB_WRITE);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
group1.add_member(array1_relative_uri, true, std::nullopt, TILEDB_ARRAY);
group1.add_member(array2_relative_uri, true, std::nullopt, TILEDB_ARRAY);
group1.add_member(group2_uri, false, std::nullopt, TILEDB_GROUP);
Expand Down Expand Up @@ -665,12 +702,24 @@ TEST_CASE_METHOD(

// Set expected
std::vector<tiledb::Object> group1_expected = {
tiledb::Object(tiledb::Object::Type::Array, array1_uri, "one"),
tiledb::Object(tiledb::Object::Type::Array, array2_uri, "two"),
tiledb::Object(tiledb::Object::Type::Group, group2_uri, "three"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array1_uri),
"one"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
"two"),
tiledb::Object(
tiledb::Object::Type::Group,
vfs_test_setup_.with_prefix(group2_uri),
"three"),
};
std::vector<tiledb::Object> group2_expected = {
tiledb::Object(tiledb::Object::Type::Array, array3_uri, "four"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array3_uri),
"four"),
};

tiledb::Group group1(ctx_, group1_uri, TILEDB_WRITE);
Expand All @@ -683,8 +732,8 @@ TEST_CASE_METHOD(
set_group_timestamp(&group2, 1);
group2.open(TILEDB_WRITE);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
group1.add_member(array1_relative_uri, true, "one", TILEDB_ARRAY);
group1.add_member(array2_relative_uri, true, "two", TILEDB_ARRAY);
group1.add_member(group2_uri, false, "three", TILEDB_GROUP);
Expand Down Expand Up @@ -801,20 +850,31 @@ TEST_CASE_METHOD(

// Set expected
std::vector<tiledb::Object> group1_expected = {
tiledb::Object(tiledb::Object::Type::Array, array1_uri, "one"),
tiledb::Object(tiledb::Object::Type::Array, array2_uri, "two"),
nameless_uri ?
tiledb::Object(tiledb::Object::Type::Array, array2_uri, nullopt) :
tiledb::Object(tiledb::Object::Type::Array, array2_uri, "three"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array1_uri),
"one"),
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
"two"),
nameless_uri ? tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
nullopt) :
tiledb::Object(
tiledb::Object::Type::Array,
vfs_test_setup_.with_prefix(array2_uri),
"three"),
};

tiledb::Group group1(ctx_, group1_uri, TILEDB_WRITE);
group1.close();
set_group_timestamp(&group1, 1);
group1.open(TILEDB_WRITE);

bool add_by_type = GENERATE(true, false);
if (add_by_type) {
bool add_with_type = GENERATE(true, false);
if (add_with_type) {
group1.add_member(array1_relative_uri, true, "one", TILEDB_ARRAY);
group1.add_member(array2_relative_uri, true, "two", TILEDB_ARRAY);
group1.add_member(
Expand Down
62 changes: 62 additions & 0 deletions test/support/src/vfs_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ class SupportedFs {
* @return true if local, false if not
*/
virtual bool is_local() = 0;

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
virtual std::string file_prefix() = 0;
};

/**
Expand Down Expand Up @@ -238,6 +246,16 @@ class SupportedFsS3 : public SupportedFs {
return false;
}

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
inline std::string file_prefix() {
return "";
}

private:
/* ********************************* */
/* ATTRIBUTES */
Expand Down Expand Up @@ -324,6 +342,16 @@ class SupportedFsHDFS : public SupportedFs {
return false;
}

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
inline std::string file_prefix() {
return "";
}

private:
/* ********************************* */
/* ATTRIBUTES */
Expand Down Expand Up @@ -404,6 +432,16 @@ class SupportedFsAzure : public SupportedFs {
return false;
}

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
inline std::string file_prefix() {
return "";
}

private:
/* ********************************* */
/* ATTRIBUTES */
Expand Down Expand Up @@ -489,6 +527,16 @@ class SupportedFsGCS : public SupportedFs {
return false;
}

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
inline std::string file_prefix() {
return "";
}

private:
/* ********************************* */
/* ATTRIBUTES */
Expand Down Expand Up @@ -677,6 +725,16 @@ class SupportedFsMem : public SupportedFs {
return true;
}

/**
* Get the name of the filesystem's file prefix. Applies only to local
* filesystems
*
* @return string prefix name
*/
inline std::string file_prefix() {
return "";
}

private:
/* ********************************* */
/* ATTRIBUTES */
Expand Down Expand Up @@ -934,6 +992,10 @@ struct VFSTestSetup {
return uri;
}

std::string with_prefix(const std::string& array_name) {
return fs_vec[0]->file_prefix() + array_name;
}

Context ctx() {
return Context(ctx_c, false);
}
Expand Down

0 comments on commit 1e7e70e

Please sign in to comment.