DbResultTest.cc 1.0 KB

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