25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

131 lines
3.5 KiB

  1. #include <gtest/gtest.h>
  2. #include <cpphibernate.h>
  3. #include <cpphibernate/driver/mariadb.h>
  4. using namespace ::cpphibernate;
  5. struct test1
  6. {
  7. uuid id;
  8. std::string str_data;
  9. string<64> str64_data;
  10. };
  11. struct test2
  12. {
  13. uuid id;
  14. uint8_t u8_data;
  15. int8_t i8_data;
  16. uint16_t u16_data;
  17. int16_t i16_data;
  18. };
  19. struct test3
  20. {
  21. uuid id;
  22. uint32_t u32_data;
  23. int32_t i32_data;
  24. uint64_t u64_data;
  25. int64_t i64_data;
  26. };
  27. struct base
  28. {
  29. uuid id;
  30. std::string name;
  31. };
  32. struct derived1
  33. : public base
  34. {
  35. uuid derived1_id;
  36. test1 test1_data;
  37. };
  38. struct derived2
  39. : public base
  40. {
  41. uuid derived2_id;
  42. utl::nullable<test2> test2_nullable;
  43. std::unique_ptr<test2> test2_ptr_u;
  44. std::shared_ptr<test2> test2_ptr_s;
  45. };
  46. struct derived3
  47. : public derived1
  48. {
  49. uuid derived3_id;
  50. std::list<test3> test3_list;
  51. std::vector<test3> test3_vector;
  52. };
  53. constexpr decltype(auto) test_schema = cpphibernate_make_schema(
  54. test,
  55. cpphibernate_make_table_name(
  56. tbl_test1,
  57. test1,
  58. 1,
  59. cpphibernate_make_id (&test1::id),
  60. cpphibernate_make_field (test1, str_data),
  61. cpphibernate_make_field (test1, str64_data)
  62. ),
  63. cpphibernate_make_table_name(
  64. tbl_test2,
  65. test2,
  66. 2,
  67. cpphibernate_make_id (&test2::id),
  68. cpphibernate_make_field (test2, u8_data),
  69. cpphibernate_make_field (test2, i8_data),
  70. cpphibernate_make_field (test2, u16_data),
  71. cpphibernate_make_field (test2, i16_data)
  72. ),
  73. cpphibernate_make_table_name(
  74. tbl_test3,
  75. test3,
  76. 3,
  77. cpphibernate_make_id (&test3::id),
  78. cpphibernate_make_field (test3, u32_data),
  79. cpphibernate_make_field (test3, i32_data),
  80. cpphibernate_make_field (test3, u64_data),
  81. cpphibernate_make_field (test3, i64_data)
  82. ),
  83. cpphibernate_make_table_name(
  84. tbl_base,
  85. base,
  86. 10,
  87. cpphibernate_make_id (&base::id),
  88. cpphibernate_make_field (base, name)
  89. ),
  90. cpphibernate_make_table_name(
  91. tbl_derived1,
  92. derived1,
  93. 11,
  94. cpphibernate_make_id (&derived1::derived1_id),
  95. cpphibernate_make_field (derived1, test1_data)
  96. ),
  97. cpphibernate_make_table_name(
  98. tbl_derived2,
  99. derived2,
  100. 12,
  101. cpphibernate_make_id (&derived2::derived2_id),
  102. cpphibernate_make_field (derived2, test2_nullable),
  103. cpphibernate_make_field (derived2, test2_ptr_u),
  104. cpphibernate_make_field (derived2, test2_ptr_s)
  105. ),
  106. cpphibernate_make_table_name(
  107. tbl_derived3,
  108. derived3,
  109. 13,
  110. cpphibernate_make_id (&derived3::derived3_id),
  111. cpphibernate_make_field (derived3, test3_list),
  112. cpphibernate_make_field (derived3, test3_vector)
  113. )
  114. );
  115. TEST(CppHibernateTests, fuuu)
  116. {
  117. ::cppmariadb::connection connection(reinterpret_cast<MYSQL*>(0x1234));
  118. auto context = make_context<driver::mariadb>(test_schema, connection);
  119. std::cout << context.schema() << std::endl;
  120. }