test-feature.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // test-size.c
  3. //
  4. // Copyright (c) 2015-2015, Marcus Rohrmoser mobile Software, http://mro.name/me
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without modification, are permitted
  8. // provided that the following conditions are met:
  9. //
  10. // 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  11. // and the following disclaimer.
  12. //
  13. // 2. The software must not be used for military or intelligence or related purposes nor
  14. // anything that's in conflict with human rights as declared in http://www.un.org/en/documents/udhr/ .
  15. //
  16. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  17. // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  22. // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  23. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. //
  25. #define LIBRDF_STORAGE_SQLITE_MRO_CONVENIENCE 1
  26. #include "../rdf_storage_sqlite_mro.h"
  27. #include "mtest.h"
  28. #include <unistd.h>
  29. #include <string.h>
  30. // #include <errno.h>
  31. int tests_run = 0;
  32. static char *test_bool_defaults()
  33. {
  34. librdf_world *world = librdf_new_world();
  35. MUAssert(world, "Failed to create world");
  36. // librdf_world_open(world);
  37. librdf_init_storage_sqlite_mro(world);
  38. {
  39. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  40. "new='on', contexts='no', synchronous='off'");
  41. MUAssert(storage, "Failed to create storage");
  42. {
  43. bool value = false;
  44. MUAssert(0 == librdf_storage_get_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, &value), "not set");
  45. MUAssert(false == value, "wrong value");
  46. MUAssert(0 == librdf_storage_get_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_EXPLAIN_QUERY_PLAN, &value), "not set");
  47. MUAssert(false == value, "wrong value");
  48. MUAssert(4 == librdf_storage_get_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, &value), "not set");
  49. MUAssert(false == value, "wrong value");
  50. }
  51. librdf_free_storage(storage);
  52. }
  53. librdf_free_world(world);
  54. return NULL;
  55. }
  56. static char *test_bool_rw_ok()
  57. {
  58. librdf_world *world = librdf_new_world();
  59. MUAssert(world, "Failed to create world");
  60. // librdf_world_open(world);
  61. librdf_init_storage_sqlite_mro(world);
  62. {
  63. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  64. "new='on', contexts='no', synchronous='off'");
  65. MUAssert(storage, "Failed to create storage");
  66. {
  67. MUAssert(0 == librdf_storage_set_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, true), "hu");
  68. bool value = false;
  69. MUAssert(0 == librdf_storage_get_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, &value), "hu");
  70. MUAssert(true == value, "wrong value");
  71. }
  72. librdf_free_storage(storage);
  73. }
  74. librdf_free_world(world);
  75. return NULL;
  76. }
  77. static char *test_bool_rw_fail()
  78. {
  79. librdf_world *world = librdf_new_world();
  80. MUAssert(world, "Failed to create world");
  81. // librdf_world_open(world);
  82. librdf_init_storage_sqlite_mro(world);
  83. {
  84. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  85. "new='on', contexts='no', synchronous='off'");
  86. MUAssert(storage, "Failed to create storage");
  87. {
  88. MUAssert(3 == librdf_storage_set_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, true), "hu");
  89. bool value = false;
  90. MUAssert(4 == librdf_storage_get_feature_mro_bool(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, &value), "not set");
  91. MUAssert(false == value, "wrong value");
  92. }
  93. librdf_free_storage(storage);
  94. }
  95. librdf_free_world(world);
  96. return NULL;
  97. }
  98. static char *test_int_defaults()
  99. {
  100. librdf_world *world = librdf_new_world();
  101. MUAssert(world, "Failed to create world");
  102. // librdf_world_open(world);
  103. librdf_init_storage_sqlite_mro(world);
  104. {
  105. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  106. "new='on', contexts='no', synchronous='off'");
  107. MUAssert(storage, "Failed to create storage");
  108. {
  109. int value = -1;
  110. MUAssert(4 == librdf_storage_get_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, &value), "not set");
  111. MUAssert(false == value, "wrong value");
  112. MUAssert(0 == librdf_storage_get_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, &value), "not set");
  113. MUAssert(511 == value, "wrong value");
  114. }
  115. librdf_free_storage(storage);
  116. }
  117. librdf_free_world(world);
  118. return NULL;
  119. }
  120. static char *test_int_rw_ok()
  121. {
  122. librdf_world *world = librdf_new_world();
  123. MUAssert(world, "Failed to create world");
  124. // librdf_world_open(world);
  125. librdf_init_storage_sqlite_mro(world);
  126. {
  127. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  128. "new='on', contexts='no', synchronous='off'");
  129. MUAssert(storage, "Failed to create storage");
  130. {
  131. MUAssert(0 == librdf_storage_set_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, 0xFFFF), "hu");
  132. int value = -1;
  133. MUAssert(0 == librdf_storage_get_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQL_CACHE_MASK, &value), "not set");
  134. MUAssert(511 == value, "wrong value");
  135. }
  136. librdf_free_storage(storage);
  137. }
  138. librdf_free_world(world);
  139. return NULL;
  140. }
  141. static char *test_int_rw_fail()
  142. {
  143. librdf_world *world = librdf_new_world();
  144. MUAssert(world, "Failed to create world");
  145. // librdf_world_open(world);
  146. librdf_init_storage_sqlite_mro(world);
  147. {
  148. librdf_storage *storage = librdf_new_storage(world, LIBRDF_STORAGE_SQLITE_MRO, "tmp/test-feature.sqlite",
  149. "new='on', contexts='no', synchronous='off'");
  150. MUAssert(storage, "Failed to create storage");
  151. {
  152. MUAssert(0 == librdf_storage_set_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, true), "hu");
  153. int value = -1;
  154. MUAssert(4 == librdf_storage_get_feature_mro_int(storage, LIBRDF_STORAGE_SQLITE_MRO_FEATURE_SQLITE3_PROFILE, &value), "not set");
  155. MUAssert(false == value, "wrong value");
  156. }
  157. librdf_free_storage(storage);
  158. }
  159. librdf_free_world(world);
  160. return NULL;
  161. }
  162. static char *all_tests()
  163. {
  164. MUTestRun(test_bool_defaults);
  165. MUTestRun(test_bool_rw_ok);
  166. MUTestRun(test_bool_rw_fail);
  167. MUTestRun(test_int_defaults);
  168. MUTestRun(test_int_rw_ok);
  169. MUTestRun(test_int_rw_fail);
  170. return 0;
  171. }
  172. int main(int argc, char **argv)
  173. {
  174. char *result = all_tests();
  175. if( result != 0 ) {
  176. printf("%s\n", result);
  177. } else {
  178. printf(ANSI_COLOR_F_GREEN "✓" ANSI_COLOR_RESET " ALL TESTS PASSED\n");
  179. }
  180. printf("Tests run: %d\n", tests_run);
  181. return result != 0;
  182. }