table_impl_test.hxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef TABLE_IMPL_TEST_HXX
  2. #define TABLE_IMPL_TEST_HXX
  3. #include "test/tester.hxx"
  4. #include "libbinom/include/binom_impl/ram_storage_implementation/table_impl.hxx"
  5. #include "libbinom/include/binom_impl/query.hxx"
  6. void testTableImpl() {
  7. RAIIPerfomanceTest test_perf("Table impl test: ");
  8. SEPARATOR
  9. TEST_ANNOUNCE(Table impl test)
  10. GRP_PUSH
  11. using namespace binom;
  12. using namespace binom::priv;
  13. using namespace binom::literals;
  14. TableImplementation tbl (
  15. table{
  16. {
  17. {"ID", IndexType::unique_index},
  18. {"Name", IndexType::multi_index},
  19. {"Last name", IndexType::multi_index},
  20. {"Organization", IndexType::multi_index},
  21. {"Is admin", IndexType::multi_index}
  22. }, {
  23. multimap{
  24. {"ID", 0},
  25. {"Name", "Maksim"},
  26. {"Last name", "Shemendyuk"},
  27. {"Organization", "Grebci i galeri"},
  28. {"Is admin", true}
  29. },
  30. multimap{
  31. {"ID", 1},
  32. {"Name", "Someone"},
  33. {"Last name", "Unknown"},
  34. {"Organization", "Grebci i galeri"},
  35. {"Is admin", false}
  36. },
  37. multimap{
  38. {"ID", 2},
  39. {"Name", "Ivan"},
  40. {"Last name", "Ivanov"},
  41. {"Organization", "Grebci i galeri"},
  42. {"Is admin", true}
  43. },
  44. multimap{
  45. {"ID", 3},
  46. {"Name", "Dmitry"},
  47. {"Last name", "Igorevich"},
  48. {"Organization", "Roga i copita"},
  49. {"Is admin", true}
  50. },
  51. multimap{
  52. {"ID", 4},
  53. {"Name", "Alexey"},
  54. {"Last name", "Petrovich"},
  55. {"Organization", "Roga i copita"},
  56. {"Is admin", false}
  57. },
  58. multimap{
  59. {"ID", 5},
  60. {"Name", "Vladimir"},
  61. {"Last name", "Vladimirovich"},
  62. {"Organization", "Roga i copita"},
  63. {"Is admin", false}
  64. },
  65. multimap{
  66. {"ID", 6},
  67. {"Name", "Bill"},
  68. {"Last name", "Heits"},
  69. {"Organization", "Roga i copita"},
  70. {"Is admin", false}
  71. },
  72. multimap{
  73. {"ID", 7},
  74. {"Name", "Linus"},
  75. {"Last name", "Torvalds"},
  76. {"Organization", "Roga i copita"},
  77. {"Is admin", false}
  78. },
  79. multimap{
  80. {"ID", 8},
  81. {"Name", "Ivan"},
  82. {"Last name", "Ivanov"},
  83. {"Organization", "Roga i copita"},
  84. {"Is admin", false}
  85. }
  86. }
  87. });
  88. // tbl.remove("ID", 0);
  89. utils::printVariable(tbl.getRow("Name", "Maksim"));
  90. // tbl["ID"].ifNoError([](TableImplementation::Column& column) {
  91. // LOG(GREEN_TXT "Column finded")
  92. // utils::printVariable(column.getFirstMapByKey(1));
  93. // }).ifError([](Error err) {
  94. // LOG(RED_TXT "Column doesn't finded:" << err.what())
  95. // });
  96. // {
  97. // using namespace binom::conditions;
  98. // TEST_ANNOUNCE(Search by query - Organization = Grebci i galeri && Is admin = true || Organization = Roga i copita && Is admin = true)
  99. // GRP_PUSH
  100. // auto new_tbl = tbl.find(
  101. // ConditionQuery(cexp_list{
  102. // cexp{"Organization", op::equal, "Grebci i galeri"},
  103. // cexp{"Is admin", op::equal, true, rel::OR},
  104. // cexp{"Organization", op::equal, "Roga i copita"},
  105. // cexp{"Is admin", op::equal, false, rel::OR},
  106. // }));
  107. // for(auto field_ref : *new_tbl["ID"])
  108. // utils::printVariable(field_ref.getOwner());
  109. // GRP_POP
  110. // }
  111. TEST_ANNOUNCE(Remove by query)
  112. TableImplementation tbl_copy = tbl;
  113. SEPARATOR
  114. LOG(WHITE_TXT "Table original before remove")
  115. for(auto field_ref : *tbl["ID"])
  116. utils::printVariable(field_ref);
  117. LOG(WHITE_TXT "Try to remov by query from table original - Is amdin = true")
  118. tbl.remove(ConditionQuery{cexp{"Is admin", op::equal, true}});
  119. LOG(WHITE_TXT "Table original after remov by query - Is admin = true")
  120. for(auto field_ref : *tbl["ID"])
  121. utils::printVariable(field_ref);
  122. SEPARATOR
  123. LOG(WHITE_TXT "Table copy before remove")
  124. for(auto field_ref : *tbl_copy["Organization"])
  125. utils::printVariable(field_ref);
  126. LOG(WHITE_TXT "Try to remov by query from table copy - Is amdin = true")
  127. tbl_copy.remove(ConditionQuery{cexp{"Is admin", op::equal, true}});
  128. LOG(WHITE_TXT "Table copy after remov by query - Is admin = true")
  129. for(auto field_ref : *tbl_copy["ID"])
  130. utils::printVariable(field_ref);
  131. GRP_POP
  132. }
  133. #endif // TABLE_IMPL_TEST_HXX