diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index c4a45720f7670a9b6e7e29f885d7155decfebb62..4a3c55e9c8446d4c4f8da17d902e94014d6d747d 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -25,7 +25,8 @@ #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, SuiteApiResolver -#include <memory> // for allocator, unique_ptr +#include <iostream> +#include <memory> // for allocator, unique_ptr class test_ccaosdb : public ::testing::Test { protected: @@ -55,10 +56,10 @@ protected: caosdb_connection_connection_create_transaction(&connection, &delete_transaction); caosdb_entity_entity entity; - char id[255] = {"id"}; // NOLINT + char *id = nullptr; // NOLINT for (int i = 0; i < *count; i++) { caosdb_transaction_result_set_at(&result_set, &entity, i); - caosdb_entity_entity_get_id(&entity, id); + caosdb_entity_entity_get_id(&entity, &id); caosdb_transaction_transaction_delete_by_id(&delete_transaction, id); } @@ -269,8 +270,8 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { caosdb_entity_entity original_entity; caosdb_entity_create_entity(&original_entity); caosdb_entity_entity_set_name(&original_entity, "TestName"); - caosdb_entity_entity_set_role(&original_entity, "Property"); - caosdb_entity_entity_set_datatype(&original_entity, "TEXT"); + caosdb_entity_entity_set_role(&original_entity, "PROPERTY"); + caosdb_entity_entity_set_datatype(&original_entity, "TEXT", false, false); caosdb_transaction_transaction insert_transaction; caosdb_connection_connection_create_transaction(&connection, @@ -289,8 +290,8 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { EXPECT_EQ(*count, 1); caosdb_entity_entity inserted_entity; caosdb_transaction_result_set_at(&insert_result_set, &inserted_entity, 0); - char in[255] = {"id"}; // NOLINT - caosdb_entity_entity_get_id(&inserted_entity, in); + char *in = nullptr; // NOLINT + caosdb_entity_entity_get_id(&inserted_entity, &in); // Retrieve it again for checks and update caosdb_transaction_transaction retrieve_transaction_1; @@ -307,21 +308,29 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { EXPECT_EQ(*count, 1); caosdb_entity_entity retrieved_entity_1; caosdb_transaction_result_set_at(&retrieve_results_1, &retrieved_entity_1, 0); - char out[255] = {"id"}; // NOLINT - caosdb_entity_entity_get_id(&retrieved_entity_1, out); + char *out = nullptr; // NOLINT + caosdb_entity_entity_get_id(&retrieved_entity_1, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_entity_get_name(&original_entity, in); - caosdb_entity_entity_get_name(&retrieved_entity_1, out); + caosdb_entity_entity_get_name(&original_entity, &in); + caosdb_entity_entity_get_name(&retrieved_entity_1, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_entity_get_role(&original_entity, in); - caosdb_entity_entity_get_role(&retrieved_entity_1, out); + caosdb_entity_entity_get_role(&original_entity, &in); + caosdb_entity_entity_get_role(&retrieved_entity_1, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_entity_get_datatype(&original_entity, in); - caosdb_entity_entity_get_datatype(&retrieved_entity_1, out); + bool is_list_in[] = {false}; // NOLINT + bool is_ref_in[] = {false}; // NOLINT + caosdb_entity_entity_get_datatype(&original_entity, &in, is_ref_in, + is_list_in); + bool is_list_out[] = {false}; // NOLINT + bool is_ref_out[] = {false}; // NOLINT + caosdb_entity_entity_get_datatype(&retrieved_entity_1, &out, is_ref_out, + is_list_out); EXPECT_EQ(strcmp(in, out), 0); + EXPECT_EQ(*is_list_in, *is_list_out); + EXPECT_EQ(*is_ref_in, *is_ref_out); // Change name and update return_code = @@ -342,8 +351,8 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { EXPECT_EQ(*count, 1); caosdb_entity_entity updated_entity; caosdb_transaction_result_set_at(&update_results, &updated_entity, 0); - caosdb_entity_entity_get_id(&inserted_entity, in); - caosdb_entity_entity_get_id(&updated_entity, out); + caosdb_entity_entity_get_id(&inserted_entity, &in); + caosdb_entity_entity_get_id(&updated_entity, &out); EXPECT_EQ(strcmp(in, out), 0); // Retrieve again @@ -362,31 +371,35 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { caosdb_entity_entity retrieved_entity_2; caosdb_transaction_result_set_at(&retrieve_results_2, &retrieved_entity_2, 0); - caosdb_entity_entity_get_id(&retrieved_entity_2, out); + caosdb_entity_entity_get_id(&retrieved_entity_2, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_entity_get_name(&retrieved_entity_1, in); - caosdb_entity_entity_get_name(&retrieved_entity_2, out); + caosdb_entity_entity_get_name(&retrieved_entity_1, &in); + caosdb_entity_entity_get_name(&retrieved_entity_2, &out); EXPECT_EQ(strcmp(in, out), 0); // Doesn't have the old name anymore - caosdb_entity_entity_get_name(&original_entity, in); + caosdb_entity_entity_get_name(&original_entity, &in); EXPECT_FALSE((strcmp(in, out) == 0)); // Everything else hasn't changed - caosdb_entity_entity_get_role(&original_entity, in); - caosdb_entity_entity_get_role(&retrieved_entity_2, out); + caosdb_entity_entity_get_role(&original_entity, &in); + caosdb_entity_entity_get_role(&retrieved_entity_2, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_entity_get_datatype(&original_entity, in); - caosdb_entity_entity_get_datatype(&retrieved_entity_2, out); + caosdb_entity_entity_get_datatype(&original_entity, &in, is_ref_in, + is_list_in); + caosdb_entity_entity_get_datatype(&retrieved_entity_2, &out, is_ref_out, + is_list_out); EXPECT_EQ(strcmp(in, out), 0); + EXPECT_EQ(*is_ref_in, *is_ref_out); + EXPECT_EQ(*is_list_in, *is_list_out); // Now delete caosdb_transaction_transaction delete_transaction; caosdb_connection_connection_create_transaction(&connection, &delete_transaction); - caosdb_entity_entity_get_id(&retrieved_entity_2, in); + caosdb_entity_entity_get_id(&retrieved_entity_2, &in); caosdb_transaction_transaction_delete_by_id(&delete_transaction, in); return_code = caosdb_transaction_transaction_execute(&delete_transaction); EXPECT_EQ(return_code, 0); @@ -399,7 +412,7 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { caosdb_entity_entity deleted_entity; caosdb_transaction_result_set_at(&delete_results, &deleted_entity, 0); - caosdb_entity_entity_get_id(&deleted_entity, out); + caosdb_entity_entity_get_id(&deleted_entity, &out); EXPECT_EQ(strcmp(in, out), 0); // Try to retrieve again @@ -440,32 +453,35 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { caosdb_connection_connection_manager_get_default_connection(&connection); // Create and insert a property, ... + std::cout << "Creating a property..." << std::endl; caosdb_entity_entity original_prop; caosdb_entity_create_entity(&original_prop); caosdb_entity_entity_set_name(&original_prop, "TestProp"); - caosdb_entity_entity_set_datatype(&original_prop, "TEXT"); - caosdb_entity_entity_set_role(&original_prop, "Property"); + caosdb_entity_entity_set_role(&original_prop, "PROPERTY"); + caosdb_entity_entity_set_datatype(&original_prop, "TEXT", false, false); + std::cout << "Inserting a property..." << std::endl; caosdb_transaction_transaction prop_insertion; caosdb_connection_connection_create_transaction(&connection, &prop_insertion); caosdb_transaction_transaction_insert_entity(&prop_insertion, &original_prop); int return_code(caosdb_transaction_transaction_execute(&prop_insertion)); EXPECT_EQ(return_code, 0); + std::cout << "Checking result..." << std::endl; caosdb_transaction_result_set prop_results; caosdb_transaction_transaction_get_result_set(&prop_insertion, &prop_results); caosdb_entity_entity inserted_prop; caosdb_transaction_result_set_at(&prop_results, &inserted_prop, 0); - char prop_id[255] = {"id"}; // NOLINT - caosdb_entity_entity_get_id(&inserted_prop, prop_id); + char *prop_id = nullptr; // NOLINT + caosdb_entity_entity_get_id(&inserted_prop, &prop_id); // ... a record type with this property, ... caosdb_entity_entity original_rt; caosdb_entity_create_entity(&original_rt); caosdb_entity_entity_set_name(&original_rt, "TestType"); - caosdb_entity_entity_set_role(&original_rt, "RecordType"); + caosdb_entity_entity_set_role(&original_rt, "RECORD_TYPE"); caosdb_entity_property rt_prop; caosdb_entity_create_property(&rt_prop); @@ -482,14 +498,14 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { caosdb_transaction_transaction_get_result_set(&rt_insertion, &rt_results); caosdb_entity_entity inserted_rt; caosdb_transaction_result_set_at(&rt_results, &inserted_rt, 0); - char rt_id[255] = {"id"}; // NOLINT - caosdb_entity_entity_get_id(&inserted_rt, rt_id); + char *rt_id = nullptr; // NOLINT + caosdb_entity_entity_get_id(&inserted_rt, &rt_id); // ... and a record with this record type as a parent. caosdb_entity_entity original_rec; caosdb_entity_create_entity(&original_rec); caosdb_entity_entity_set_name(&original_rec, "TestRec"); - caosdb_entity_entity_set_role(&original_rec, "Record"); + caosdb_entity_entity_set_role(&original_rec, "RECORD"); caosdb_entity_parent rec_parent; caosdb_entity_create_parent(&rec_parent); caosdb_entity_parent_set_id(&rec_parent, rt_id); @@ -497,7 +513,7 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { caosdb_entity_property rec_prop; caosdb_entity_create_property(&rec_prop); caosdb_entity_property_set_id(&rec_prop, prop_id); - caosdb_entity_property_set_value(&rec_prop, "Bla"); + caosdb_entity_property_set_string_value(&rec_prop, "Bla"); caosdb_entity_entity_append_property(&original_rec, &rec_prop); caosdb_transaction_transaction rec_insertion; @@ -510,8 +526,8 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { caosdb_transaction_transaction_get_result_set(&rec_insertion, &rec_results); caosdb_entity_entity inserted_rec; caosdb_transaction_result_set_at(&rec_results, &inserted_rec, 0); - char rec_id[255] = {"id"}; // NOLINT - caosdb_entity_entity_get_id(&inserted_rec, rec_id); + char *rec_id = nullptr; // NOLINT + caosdb_entity_entity_get_id(&inserted_rec, &rec_id); // Retrieve the record again for comparison caosdb_transaction_transaction retrieve_transaction; @@ -526,10 +542,10 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { &retrieve_result); caosdb_entity_entity retrieved_rec; caosdb_transaction_result_set_at(&retrieve_result, &retrieved_rec, 0); - char in[255] = {"abc"}; // NOLINT - char out[255] = {"abc"}; // NOLINT - caosdb_entity_entity_get_name(&original_rec, in); - caosdb_entity_entity_get_name(&retrieved_rec, out); + char *in = nullptr; // NOLINT + char *out = nullptr; // NOLINT + caosdb_entity_entity_get_name(&original_rec, &in); + caosdb_entity_entity_get_name(&retrieved_rec, &out); EXPECT_EQ(strcmp(in, out), 0); int count[] = {0}; // NOLINT caosdb_entity_entity_get_properties_size(&retrieved_rec, count); @@ -539,19 +555,19 @@ TEST_F(test_ccaosdb, test_insert_with_prop_and_parent) { caosdb_entity_parent retrieved_parent; caosdb_entity_entity_get_parent(&retrieved_rec, &retrieved_parent, 0); - caosdb_entity_entity_get_name(&original_rt, in); - caosdb_entity_parent_get_name(&retrieved_parent, out); + caosdb_entity_entity_get_name(&original_rt, &in); + caosdb_entity_parent_get_name(&retrieved_parent, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_parent_get_id(&retrieved_parent, out); + caosdb_entity_parent_get_id(&retrieved_parent, &out); EXPECT_EQ(strcmp(rt_id, out), 0); caosdb_entity_property retrieved_property; caosdb_entity_entity_get_property(&retrieved_rec, &retrieved_property, 0); - caosdb_entity_entity_get_name(&original_prop, in); - caosdb_entity_property_get_name(&retrieved_property, out); + caosdb_entity_entity_get_name(&original_prop, &in); + caosdb_entity_property_get_name(&retrieved_property, &out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_property_get_value(&rec_prop, in); - caosdb_entity_property_get_value(&retrieved_property, out); + caosdb_entity_property_get_string_value(&rec_prop, &in); + caosdb_entity_property_get_string_value(&retrieved_property, &out); EXPECT_EQ(strcmp(in, out), 0); caosdb_transaction_delete_transaction(&retrieve_transaction);