Skip to content

Commit bd02b87

Browse files
authored
Merge pull request #325 from theasianpianist/msft-ssg-cstr
[ssg]: Use C++ strings for text handling (#18596)
2 parents 6bfb85a + 1e1876a commit bd02b87

File tree

4 files changed

+148
-177
lines changed

4 files changed

+148
-177
lines changed

src/systemd-sonic-generator/Makefile

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ CC=gcc
22
CFLAGS += -std=gnu99 -D_GNU_SOURCE
33

44
CXX=g++
5-
CXXFLAGS += -std=c++11 -D_GNU_SOURCE
6-
LDFLAGS += -lpthread -lboost_filesystem -lboost_system -lgtest
5+
CXXFLAGS += -std=c++11 -D_GNU_SOURCE -I ./
6+
LDFLAGS += -l stdc++ -lpthread -lboost_filesystem -lboost_system -lgtest
77

88
BINARY = systemd-sonic-generator
99

10-
$(BINARY): systemd-sonic-generator.c
10+
$(BINARY): systemd-sonic-generator.cpp
1111
rm -f ./systemd-sonic-generator
1212

13-
$(CC) $(CFLAGS) -o $@ $^
13+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
1414

1515
install: $(BINARY)
1616
mkdir -p $(DESTDIR)
@@ -24,10 +24,12 @@ test: ssg_test
2424
./ssg_test
2525

2626
ssg_test: ssg-test.cc systemd-sonic-generator.o
27-
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
27+
$(CXX) $(CXXFLAGS) -ggdb -o $@ $^ $(LDFLAGS)
28+
29+
systemd-sonic-generator.o: systemd-sonic-generator.cpp
30+
$(CXX) $(CXXFLAGS) -ggdb -D_SSG_UNITTEST -o $@ -c $^
2831

29-
systemd-sonic-generator.o: systemd-sonic-generator.c
30-
$(CC) $(CFLAGS) -D_SSG_UNITTEST -o $@ -c $^
32+
all: $(BINARY) test
3133

3234
clean:
3335
rm -f ./systemd-sonic-generator

src/systemd-sonic-generator/ssg-test.cc

+4-7
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ class SsgMainTest : public SsgFunctionTest {
181181

182182
/* Find a string in a file */
183183
bool find_string_in_file(std::string str,
184-
std::string file_name,
185-
int num_asics) {
184+
std::string file_name) {
186185
bool found = false;
187186
std::string line;
188187

@@ -214,7 +213,7 @@ class SsgMainTest : public SsgFunctionTest {
214213
/* Run once for single instance */
215214
finished = true;
216215
}
217-
EXPECT_EQ(find_string_in_file(str_t, target, num_asics),
216+
EXPECT_EQ(find_string_in_file(str_t, target),
218217
expected_result)
219218
<< "Error validating " + str_t + " in " + target;
220219
}
@@ -460,9 +459,8 @@ TEST_F(SsgFunctionTest, insert_instance_number) {
460459
char input[] = "test@.service";
461460
for (int i = 0; i <= 100; ++i) {
462461
std::string out = "test@" + std::to_string(i) + ".service";
463-
char* ret = insert_instance_number(input, i);
464-
ASSERT_NE(ret, nullptr);
465-
EXPECT_STREQ(ret, out.c_str());
462+
std::string ret = insert_instance_number(input, i);
463+
EXPECT_EQ(ret, out);
466464
}
467465
}
468466

@@ -513,7 +511,6 @@ TEST_F(SsgFunctionTest, get_unit_files) {
513511

514512
/* TEST ssg_main() argv error */
515513
TEST_F(SsgMainTest, ssg_main_argv) {
516-
FILE* fp;
517514
std::vector<char*> argv_;
518515
std::vector<std::string> arguments = {
519516
"ssg_main",

0 commit comments

Comments
 (0)