1 #include <iostream>
2 #include <string>
3 #include "testlib/testlib_test.h"
4 #include "sample_database.h"
5 #include <brdb/brdb_value.h>
6 #include <brdb/brdb_tuple.h>
7 #include <brdb/brdb_relation.h>
8 #include <brdb/brdb_database.h>
9 #ifdef _MSC_VER
10 # include "vcl_msvc_warnings.h"
11 #endif
12
test_database()13 static void test_database()
14 {
15
16 //////////////////////////////////////////////////////////////////////////////////
17 //////// test the binary IO function of database
18 //////////////////////////////////////////////////////////////////////////////////
19 std::cout << "Warning: Binary I/O test deactivated because of failures" <<std::endl;
20
21 #if 0
22 brdb_database_sptr test_db1 = generate_sample_database();
23
24 std::cout << "test_db1: " << std::endl;
25 test_db1->print();
26 std::cout << std::endl;
27
28 vsl_b_ofstream out_stream("test_database_bio.vsl");
29 if (!out_stream){
30 std::cerr<<"Failed to open test_database_bio.vsl for output.\n";
31 }
32 std::cout << "Opened file successfully " << std::endl;
33
34 test_db1->b_write(out_stream);
35 out_stream.close();
36 test_db1->clear();
37
38 brdb_database_sptr test_db = new brdb_database();
39
40 vsl_b_ifstream in_stream("test_database_bio.vsl");
41 if (!in_stream){
42 std::cerr<<"Failed to open test_relation_bio.vsl for input.\n";
43 }
44 std::cout << "Opened file successfully " << std::endl;
45
46 test_db->b_read(in_stream);
47 in_stream.close();
48
49 test_db->print();
50
51 TEST("Binary IO read and write", true, true);
52 #endif
53
54 brdb_database_sptr test_db = generate_sample_database();
55
56 TEST("construct", true, true);
57
58 std::set<std::string> all_relation_names = test_db->get_all_relation_names();
59 std::cout << " Relation names: " << std::endl;
60 for (const auto & all_relation_name : all_relation_names)
61 {
62 std::cout << " " << all_relation_name << std::endl;
63 }
64 std::cout << std::endl;
65 TEST("get_all_relation_names()", true, true);
66
67 test_db->print();
68
69 TEST("print()", true, true);
70
71 TEST("size()", (test_db->size() == 3), true);
72
73 TEST("exists()", (test_db->exists("department")), true);
74
75 brdb_relation_sptr r3 = test_db->get_relation("department");
76 TEST("get_relation()", r3 == nullptr, false);
77
78 test_db->remove_relation("department");
79 TEST("remove_relation()", test_db->exists("department"), false);
80
81 test_db->add_relation("new_department", r3);
82 TEST("add_new_relation()", test_db->exists("new_department"), true);
83
84 brdb_tuple_sptr r3_new_tuple = new brdb_tuple(999, std::string("Engineering Department"));
85 unsigned int prev_size = r3->size();
86 bool added = test_db->add_tuple("new_department", r3_new_tuple);
87 TEST("add_tuple()", added && r3->size() == prev_size+1, true);
88
89 test_db->clear();
90 TEST("clear()", (test_db->size() == 0), true);
91
92 TEST("empty()", (test_db->empty()), true);
93 }
94
95 TESTMAIN(test_database);
96