gem5  v22.1.0.0
match.test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 The Regents of the University of California
3  * All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <gtest/gtest.h>
30 
31 #include "base/match.hh"
32 
33 using namespace gem5;
34 
35 TEST(MatchTest, Add)
36 {
37  /*
38  * ObjectMatch.add will add all the expressions from one ObjectMatch to
39  * the other.
40  */
41  ObjectMatch object_match_1("token1.token2");
42  ObjectMatch object_match_2("token3");
43  ObjectMatch object_match_3;
44 
45  object_match_3.add(object_match_1);
46  object_match_3.add(object_match_2);
47 
49  object_match_3.getExpressions();
50 
51  EXPECT_EQ(2, expressions.size());
52  EXPECT_EQ(2, expressions[0].size());
53  EXPECT_EQ(1, expressions[1].size());
54 
55  EXPECT_EQ(expressions[0][0], "token1");
56  EXPECT_EQ(expressions[0][1], "token2");
57  EXPECT_EQ(expressions[1][0], "token3");
58 }
59 
60 TEST(MatchTest, SetExpression)
61 {
62  ObjectMatch object_match;
63  object_match.setExpression("A.B.C.D");
64 
66  object_match.getExpressions();
67 
68  EXPECT_EQ(1, expressions.size());
69  EXPECT_EQ(4, expressions[0].size());
70 
71  EXPECT_EQ("A", expressions[0][0]);
72  EXPECT_EQ("B", expressions[0][1]);
73  EXPECT_EQ("C", expressions[0][2]);
74  EXPECT_EQ("D", expressions[0][3]);
75 }
76 
77 TEST(MatchTest, SetExpressionVector)
78 {
79  ObjectMatch object_match;
80 
82  to_add.push_back("A.B.C.D");
83  to_add.push_back("E.F.G");
84 
85  object_match.setExpression(to_add);
86 
88  object_match.getExpressions();
89 
90  EXPECT_EQ(2, expressions.size());
91  EXPECT_EQ(4, expressions[0].size());
92  EXPECT_EQ(3, expressions[1].size());
93 
94  EXPECT_EQ("A", expressions[0][0]);
95  EXPECT_EQ("B", expressions[0][1]);
96  EXPECT_EQ("C", expressions[0][2]);
97  EXPECT_EQ("D", expressions[0][3]);
98  EXPECT_EQ("E", expressions[1][0]);
99  EXPECT_EQ("F", expressions[1][1]);
100  EXPECT_EQ("G", expressions[1][2]);
101 }
102 
103 TEST(MatchTest, SimpleMatch)
104 {
105  ObjectMatch object_match("this.is.a.perfect.match");
106  EXPECT_TRUE(object_match.match("this.is.a.perfect.match"));
107 }
108 
109 TEST(MatchTest, SimpleMismatch)
110 {
111  ObjectMatch object_match("this.is.a.perfect.match");
112  EXPECT_FALSE(object_match.match("this.is.a.perfect.--"));
113 }
114 
115 TEST(MatchTest, MultipleExpressionsMatch)
116 {
117  ObjectMatch object_match;
118  std::vector<std::string> expressions;
119  expressions.push_back("A.B.C.D");
120  expressions.push_back("E.F.G");
121  object_match.setExpression(expressions);
122 
123  EXPECT_TRUE(object_match.match("A.B.C.D"));
124  EXPECT_TRUE(object_match.match("E.F.G"));
125 }
126 
127 TEST(MatchTest, MultipleExpressionsMismatch)
128 {
129  ObjectMatch object_match;
130  std::vector<std::string> expressions;
131  expressions.push_back("A.B.C.D");
132  expressions.push_back("E.F.G");
133  object_match.setExpression(expressions);
134 
135  EXPECT_FALSE(object_match.match("B.C.D"));
136  EXPECT_FALSE(object_match.match("D.E.F.G"));
137 }
138 
139 TEST(MatchTest, WildCardMatch)
140 {
141  ObjectMatch object_match("this.is.a.*.match");
142 
143  /*
144  * Note: the wildcard token can represent an empty token.
145  */
146  EXPECT_TRUE(object_match.match("this.is.a.match"));
147  EXPECT_TRUE(object_match.match("this.is.a.perfect.match"));
148  EXPECT_TRUE(object_match.match("this.is.a.great.match"));
149 }
150 
151 TEST(MatchTest, WildCardMismatch)
152 {
153  ObjectMatch object_match("this.is.a.*.match");
154 
155  EXPECT_FALSE(object_match.match("this.is.a.bla.bla.match"));
156  EXPECT_FALSE(object_match.match("this.is.a.great.match--"));
157 }
158 
159 TEST(MatchTest, TokensEmptyNoMatch)
160 {
161  ObjectMatch object_match;
162  EXPECT_FALSE(object_match.match("token1"));
163 }
ObjectMatch contains a vector of expressions.
Definition: match.hh:57
void setExpression(const std::string &expression)
Definition: match.cc:53
void add(const ObjectMatch &other)
Definition: match.cc:47
std::vector< std::vector< std::string > > getExpressions()
Definition: match.cc:107
bool match(const std::string &name) const
Definition: match.hh:69
STL vector class.
Definition: stl.hh:37
TEST(MatchTest, Add)
Definition: match.test.cc:35
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1