DbResultTest.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright: All Rights Reserved
  2. // Author: egametang@gmail.com (tanghai)
  3. #include <memory>
  4. #include <gtest/gtest.h>
  5. #include <gflags/gflags.h>
  6. #include <glog/logging.h>
  7. #include "Orm/DbHelper.h"
  8. #include "Orm/DbResult.h"
  9. #include "Orm/Select.h"
  10. #include "Orm/Person.pb.h"
  11. #include "Orm/Exception.h"
  12. namespace Egametang {
  13. class DbResultTest: public testing::Test
  14. {
  15. };
  16. TEST_F(DbResultTest, One)
  17. {
  18. try
  19. {
  20. DbHelper dbHelper("tcp://127.0.0.1:3306", "root", "111111");
  21. DbResultPtr result = dbHelper.Execute(
  22. Select<Person>(Column("*")).
  23. Where(Column("age") > 10)
  24. );
  25. auto person = std::make_shared<Person>();
  26. result->One(person);
  27. ASSERT_EQ(26, person->age());
  28. }
  29. catch (const Exception& e)
  30. {
  31. if (const std::string* str = boost::get_error_info<ConnectionErrStr>(e))
  32. {
  33. LOG(FATAL) << *str;
  34. }
  35. if (const std::string* str = boost::get_error_info<SqlNoDataErrStr>(e))
  36. {
  37. LOG(WARNING) << *str;
  38. }
  39. }
  40. }
  41. } // namespace Egametang
  42. int main(int argc, char* argv[])
  43. {
  44. testing::InitGoogleTest(&argc, argv);
  45. google::InitGoogleLogging(argv[0]);
  46. google::ParseCommandLineFlags(&argc, &argv, true);
  47. return RUN_ALL_TESTS();
  48. }