statement_id_unittest.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sql/statement_id.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace sql {
  7. namespace {
  8. class SqlStatementIdTest : public testing::Test {
  9. protected:
  10. // This test takes advantage of the fact that statement IDs are logically
  11. // (file, line) tuples, and are compared lexicographically.
  12. SqlStatementIdTest()
  13. : id1_(SQL_FROM_HERE), // file statement_id_unittest.cc, line L
  14. id2_(SQL_FROM_HERE), // file statement_id_unittest.cc, line L+1
  15. id3_(SQL_FROM_HERE) { // file statement_id_unittest.cc, line L+2
  16. }
  17. StatementID id1_;
  18. StatementID id2_;
  19. StatementID id3_;
  20. };
  21. TEST_F(SqlStatementIdTest, LessThan) {
  22. EXPECT_FALSE(id1_ < id1_);
  23. EXPECT_FALSE(id2_ < id2_);
  24. EXPECT_FALSE(id3_ < id3_);
  25. EXPECT_LT(id1_, id2_);
  26. EXPECT_LT(id1_, id3_);
  27. EXPECT_LT(id2_, id3_);
  28. EXPECT_FALSE(id2_ < id1_);
  29. EXPECT_FALSE(id3_ < id1_);
  30. EXPECT_FALSE(id3_ < id2_);
  31. }
  32. TEST_F(SqlStatementIdTest, CopyConstructor) {
  33. StatementID id2_copy = id2_;
  34. EXPECT_FALSE(id2_copy < id2_);
  35. EXPECT_FALSE(id2_ < id2_copy);
  36. EXPECT_LT(id1_, id2_copy);
  37. EXPECT_LT(id2_copy, id3_);
  38. }
  39. TEST_F(SqlStatementIdTest, CopyAssignment) {
  40. StatementID id2_copy(SQL_FROM_HERE);
  41. // The new ID should be different from ID2.
  42. EXPECT_TRUE(id2_copy < id2_ || id2_ < id2_copy);
  43. id2_copy = id2_;
  44. EXPECT_FALSE(id2_copy < id2_);
  45. EXPECT_FALSE(id2_ < id2_copy);
  46. EXPECT_LT(id1_, id2_copy);
  47. EXPECT_LT(id2_copy, id3_);
  48. }
  49. } // namespace
  50. } // namespace sql