Skip to content

Commit a769fed

Browse files
authored
Merge pull request #326 from theasianpianist/msft-202205-ssg-cstr
[202205][ssg]: Use C++ strings for text handling
2 parents 51a6a31 + df47393 commit a769fed

File tree

4 files changed

+150
-179
lines changed

4 files changed

+150
-179
lines changed

src/systemd-sonic-generator/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
CC=gcc
22
CFLAGS=-std=gnu99 -D_GNU_SOURCE
33

4-
CPP=g++
5-
CPPFLAGS=-std=c++11 -D_GNU_SOURCE
6-
LFLAGS=-lpthread -lboost_filesystem -lboost_system -lgtest
4+
CXX=g++
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
MAIN_TARGET = $(BINARY)_1.0.0_$(CONFIGURED_ARCH).deb
@@ -13,10 +13,10 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
1313
mv ../$(MAIN_TARGET) $(DEST)/
1414
rm ../$(BINARY)-* ../$(BINARY)_*
1515

16-
$(BINARY): systemd-sonic-generator.c
16+
$(BINARY): systemd-sonic-generator.cpp
1717
rm -f ./systemd-sonic-generator
1818

19-
$(CC) $(CFLAGS) -o $@ $^
19+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
2020

2121
install: $(BINARY)
2222
mkdir -p $(DESTDIR)
@@ -30,10 +30,12 @@ test: ssg_test
3030
./ssg_test
3131

3232
ssg_test: ssg-test.cc systemd-sonic-generator.o
33-
$(CPP) $(CPPFLAGS) -o $@ $^ $(LFLAGS)
33+
$(CXX) $(CXXFLAGS) -ggdb -o $@ $^ $(LDFLAGS)
3434

35-
systemd-sonic-generator.o: systemd-sonic-generator.c
36-
$(CC) $(CFLAGS) -D_SSG_UNITTEST -o $@ -c $^
35+
systemd-sonic-generator.o: systemd-sonic-generator.cpp
36+
$(CXX) $(CXXFLAGS) -ggdb -D_SSG_UNITTEST -o $@ -c $^
37+
38+
all: $(BINARY) test
3739

3840
clean:
3941
rm -f ./systemd-sonic-generator

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

Lines changed: 4 additions & 7 deletions
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[] = "[email protected]";
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)