Avi Drissman | 69b874f | 2022-09-15 19:11:14 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Victor Costan | 12daa3ac9 | 2018-07-19 01:05:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "sql/statement_id.h" |
| 6 | #include "testing/gtest/include/gtest/gtest.h" |
| 7 | |
| 8 | namespace sql { |
| 9 | |
| 10 | namespace { |
| 11 | |
| 12 | class SqlStatementIdTest : public testing::Test { |
| 13 | protected: |
| 14 | // This test takes advantage of the fact that statement IDs are logically |
| 15 | // (file, line) tuples, and are compared lexicographically. |
| 16 | SqlStatementIdTest() |
| 17 | : id1_(SQL_FROM_HERE), // file statement_id_unittest.cc, line L |
| 18 | id2_(SQL_FROM_HERE), // file statement_id_unittest.cc, line L+1 |
| 19 | id3_(SQL_FROM_HERE) { // file statement_id_unittest.cc, line L+2 |
| 20 | } |
| 21 | |
| 22 | StatementID id1_; |
| 23 | StatementID id2_; |
| 24 | StatementID id3_; |
| 25 | }; |
| 26 | |
| 27 | TEST_F(SqlStatementIdTest, LessThan) { |
| 28 | EXPECT_FALSE(id1_ < id1_); |
| 29 | EXPECT_FALSE(id2_ < id2_); |
| 30 | EXPECT_FALSE(id3_ < id3_); |
| 31 | |
| 32 | EXPECT_LT(id1_, id2_); |
| 33 | EXPECT_LT(id1_, id3_); |
| 34 | EXPECT_LT(id2_, id3_); |
| 35 | |
| 36 | EXPECT_FALSE(id2_ < id1_); |
| 37 | EXPECT_FALSE(id3_ < id1_); |
| 38 | EXPECT_FALSE(id3_ < id2_); |
| 39 | } |
| 40 | |
| 41 | TEST_F(SqlStatementIdTest, CopyConstructor) { |
| 42 | StatementID id2_copy = id2_; |
| 43 | |
| 44 | EXPECT_FALSE(id2_copy < id2_); |
| 45 | EXPECT_FALSE(id2_ < id2_copy); |
| 46 | |
| 47 | EXPECT_LT(id1_, id2_copy); |
| 48 | EXPECT_LT(id2_copy, id3_); |
| 49 | } |
| 50 | |
| 51 | TEST_F(SqlStatementIdTest, CopyAssignment) { |
| 52 | StatementID id2_copy(SQL_FROM_HERE); |
| 53 | |
| 54 | // The new ID should be different from ID2. |
| 55 | EXPECT_TRUE(id2_copy < id2_ || id2_ < id2_copy); |
| 56 | |
| 57 | id2_copy = id2_; |
| 58 | |
| 59 | EXPECT_FALSE(id2_copy < id2_); |
| 60 | EXPECT_FALSE(id2_ < id2_copy); |
| 61 | |
| 62 | EXPECT_LT(id1_, id2_copy); |
| 63 | EXPECT_LT(id2_copy, id3_); |
| 64 | } |
| 65 | |
| 66 | } // namespace |
| 67 | |
| 68 | } // namespace sql |