Skip to content

Commit 5c79e21

Browse files
test: replace assert with GoogleTest assertions
1 parent 883d4ea commit 5c79e21

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

targets/simple_switch_grpc/tests/example.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <google/rpc/code.pb.h>
1414
#include <p4/v1/p4runtime.grpc.pb.h>
1515

16+
#include <gtest/gtest.h>
17+
1618
#include <google/protobuf/util/message_differencer.h>
1719

1820
#include <fstream>
@@ -66,8 +68,8 @@ test() {
6668
stream->Write(request);
6769
p4v1::StreamMessageResponse response;
6870
stream->Read(&response);
69-
assert(response.update_case() == p4v1::StreamMessageResponse::kArbitration);
70-
assert(response.arbitration().status().code() == ::google::rpc::Code::OK);
71+
ASSERT_EQ(response.update_case(), p4v1::StreamMessageResponse::kArbitration);
72+
ASSERT_EQ(response.arbitration().status().code(), ::google::rpc::Code::OK);
7173
}
7274

7375
{
@@ -87,9 +89,9 @@ test() {
8789
ClientContext context;
8890
auto status = pi_stub_->SetForwardingPipelineConfig(
8991
&context, request, &rep);
90-
assert(status.ok());
92+
ASSERT_TRUE(status.ok());
9193
auto *released_p4info = config->release_p4info();
92-
assert(released_p4info == &p4info);
94+
ASSERT_EQ(released_p4info, &p4info);
9395
}
9496

9597
auto t_id = get_table_id(p4info, "ipv4_lpm");
@@ -131,9 +133,9 @@ test() {
131133
ClientContext context;
132134
p4v1::WriteResponse rep;
133135
auto status = pi_stub_->Write(&context, request, &rep);
134-
assert(status.ok());
136+
ASSERT_TRUE(status.ok());
135137
auto *released_entity = update->release_entity();
136-
assert(released_entity == &entity);
138+
ASSERT_EQ(released_entity, &entity);
137139
}
138140

139141
auto read_one = [&dev_id, &pi_stub_, &table_entry] () {
@@ -147,17 +149,17 @@ test() {
147149
p4v1::ReadResponse rep;
148150
reader->Read(&rep);
149151
auto status = reader->Finish();
150-
assert(status.ok());
152+
ASSERT_TRUE(status.ok());
151153
auto *released_table_entry = entity->release_table_entry();
152-
assert(released_table_entry == table_entry);
154+
ASSERT_EQ(released_table_entry, table_entry);
153155
return rep;
154156
};
155157

156158
// get entry, check it is the one we added
157159
{
158160
auto rep = read_one();
159-
assert(rep.entities().size() == 1);
160-
assert(MessageDifferencer::Equals(entity, rep.entities().Get(0)));
161+
ASSERT_EQ(rep.entities().size(), 1);
162+
ASSERT_TRUE(MessageDifferencer::Equals(entity, rep.entities().Get(0)));
161163
}
162164

163165
// remove entry
@@ -171,23 +173,23 @@ test() {
171173
ClientContext context;
172174
p4v1::WriteResponse rep;
173175
auto status = pi_stub_->Write(&context, request, &rep);
174-
assert(status.ok());
176+
ASSERT_TRUE(status.ok());
175177
auto *released_entity = update->release_entity();
176-
assert(released_entity == &entity);
178+
ASSERT_EQ(released_entity, &entity);
177179
}
178180

179181
// check entry is indeed gone
180182
{
181183
auto rep = read_one();
182-
assert(rep.entities().size() == 0);
184+
ASSERT_EQ(rep.entities().size(), 0);
183185
}
184186

185187
{
186188
stream->WritesDone();
187189
p4v1::StreamMessageResponse response;
188190
while (stream->Read(&response)) { }
189191
auto status = stream->Finish();
190-
assert(status.ok());
192+
ASSERT_TRUE(status.ok());
191193
}
192194

193195
return 0;

targets/simple_switch_grpc/tests/utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <google/protobuf/io/zero_copy_stream_impl.h>
1414
#include <google/protobuf/text_format.h>
15+
#include <gtest/gtest.h>
1516

1617
#include <cassert>
1718
#include <fstream>
@@ -85,7 +86,7 @@ int get_act_prof_id(const p4configv1::P4Info &p4info,
8586
p4configv1::P4Info parse_p4info(const char *path) {
8687
p4configv1::P4Info p4info;
8788
std::ifstream istream(path);
88-
assert(istream.good());
89+
ASSERT_TRUE(istream.good());
8990
// p4info.ParseFromIstream(&istream);
9091
google::protobuf::io::IstreamInputStream istream_(&istream);
9192
google::protobuf::TextFormat::Parse(&istream_, &p4info);

0 commit comments

Comments
 (0)