forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data_test.cc
More file actions
95 lines (81 loc) · 2.69 KB
/
Copy pathtest_data_test.cc
File metadata and controls
95 lines (81 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "google/api/expr/v1beta1/value.pb.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "testutil/test_data_io.h"
#include "testutil/test_data_util.h"
#include "testdata/test_data.pb.h"
namespace google {
namespace api {
namespace expr {
namespace testutil {
using testdata::TestValue;
/**
* Test class for all pairs of values in "unique_values"
*/
class UniqueValuesTest
: public ::testing::TestWithParam<std::pair<TestValue, TestValue>> {
protected:
UniqueValuesTest() { v1beta1::InitValueDifferencer(&v1beta1_differ_); }
bool Equivalent(const v1beta1::ExprValue& lhs,
const v1beta1::ExprValue& rhs) {
return v1beta1_differ_.Compare(lhs, rhs);
}
void ExpectEquivalent(bool expected, const TestValue& lhs,
const TestValue& rhs) {
for (const auto& lhs_value : lhs.v1beta1()) {
SCOPED_TRACE(lhs_value.ShortDebugString());
for (const auto& rhs_value : rhs.v1beta1()) {
SCOPED_TRACE(rhs_value.ShortDebugString());
EXPECT_EQ(expected, Equivalent(lhs_value, rhs_value));
}
}
}
private:
google::protobuf::util::MessageDifferencer v1beta1_differ_;
};
/**
* Tests that the values in "unqiue_values" are not equivalent to each other.
*/
TEST_P(UniqueValuesTest, NotEquivalent) {
ExpectEquivalent(false, GetParam().first, GetParam().second);
}
INSTANTIATE_TEST_SUITE_P(
UniqueValues, UniqueValuesTest,
::testing::ValuesIn(AllPairs(ReadTestData("unique_values").test_values())),
TestDataParamName());
/**
* Test class for TestValue invariants.
*/
class TestValueTest : public ::testing::TestWithParam<TestValue> {
protected:
TestValueTest() { v1beta1::InitValueDifferencer(&v1beta1_differ_); }
::testing::AssertionResult Equivalent(const v1beta1::ExprValue& lhs,
const v1beta1::ExprValue& rhs) {
std::string diff;
v1beta1_differ_.ReportDifferencesToString(&diff);
if (v1beta1_differ_.Compare(lhs, rhs)) {
return ::testing::AssertionSuccess();
}
return ::testing::AssertionFailure() << diff;
}
private:
google::protobuf::util::MessageDifferencer v1beta1_differ_;
};
/**
* Tests that all values within a given TestValue are equivalent to each other.
*/
TEST_P(TestValueTest, Equivalent) {
const auto& first = GetParam().v1beta1(0);
for (const auto& value : GetParam().v1beta1()) {
SCOPED_TRACE(value.ShortDebugString());
EXPECT_TRUE(Equivalent(first, value));
}
}
INSTANTIATE_TEST_SUITE_P(
UniqueValues, TestValueTest,
::testing::ValuesIn(ReadTestData("unique_values").test_values().values()),
TestDataParamName());
} // namespace testutil
} // namespace expr
} // namespace api
} // namespace google