Skip to content

Commit c13e0d5

Browse files
committed
Simplified unit test naming: testText[size], testRandom[seedvalue]
Modidifed unit test to have their expected and actual files be named according to the test name. ie: TestExtraction.testText10() has an expected file named generated_files\testText10\testText10.bin and an actual file named generated_files\testText10\testText10.output Removed --fill=predictable argument from testfilegenerator.cpp. Created new --seed=value argument for testfilegenerator.cpp which is now replacing the fill=predictable argument.
1 parent ab204b2 commit c13e0d5

File tree

7 files changed

+247
-100
lines changed

7 files changed

+247
-100
lines changed

msvc/bin2cpp_unittest.vcxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107
<ClCompile Include="..\test\main.cpp" />
108108
<ClCompile Include="..\test\TestExtraction.cpp" />
109109
<ClCompile Include="generated_files\testHtml100000\_testHtml100000.cpp" />
110-
<ClCompile Include="generated_files\testPredictable100000\_testPredictable100000.cpp" />
111-
<ClCompile Include="generated_files\testPredictable1000\_testPredictable1000.cpp" />
112-
<ClCompile Include="generated_files\testRandom100000\_testRandom100000.cpp" />
110+
<ClCompile Include="generated_files\testRandom1\_testRandom1.cpp" />
111+
<ClCompile Include="generated_files\testRandom2\_testRandom2.cpp" />
113112
<ClCompile Include="generated_files\testSequential10MB\_testSequential10MB.cpp" />
114-
<ClCompile Include="generated_files\testSmall10\_testSmall10.cpp" />
115113
<ClCompile Include="generated_files\testText100000\_testText100000.cpp" />
114+
<ClCompile Include="generated_files\testText1000\_testText1000.cpp" />
115+
<ClCompile Include="generated_files\testText10\_testText10.cpp" />
116116
</ItemGroup>
117117
<ItemGroup>
118118
<None Include="bin2cppTest.x86.debug.xml" />
@@ -132,12 +132,12 @@
132132
<ClInclude Include="..\test\gtesthelper.h" />
133133
<ClInclude Include="..\test\TestExtraction.h" />
134134
<ClInclude Include="generated_files\testHtml100000\_testHtml100000.h" />
135-
<ClInclude Include="generated_files\testPredictable100000\_testPredictable100000.h" />
136-
<ClInclude Include="generated_files\testPredictable1000\_testPredictable1000.h" />
137-
<ClInclude Include="generated_files\testRandom100000\_testRandom100000.h" />
135+
<ClInclude Include="generated_files\testRandom1\_testRandom1.h" />
136+
<ClInclude Include="generated_files\testRandom2\_testRandom2.h" />
138137
<ClInclude Include="generated_files\testSequential10MB\_testSequential10MB.h" />
139-
<ClInclude Include="generated_files\testSmall10\_testSmall10.h" />
140138
<ClInclude Include="generated_files\testText100000\_testText100000.h" />
139+
<ClInclude Include="generated_files\testText1000\_testText1000.h" />
140+
<ClInclude Include="generated_files\testText10\_testText10.h" />
141141
</ItemGroup>
142142
<ItemGroup>
143143
<ProjectReference Include="bin2cpp.vcxproj">

msvc/bin2cpp_unittest.vcxproj.filters

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@
3333
<ClCompile Include="..\test\TestExtraction.cpp">
3434
<Filter>Tests</Filter>
3535
</ClCompile>
36-
<ClCompile Include="generated_files\testRandom100000\_testRandom100000.cpp">
36+
<ClCompile Include="generated_files\testHtml100000\_testHtml100000.cpp">
3737
<Filter>Generated Files</Filter>
3838
</ClCompile>
39-
<ClCompile Include="generated_files\testHtml100000\_testHtml100000.cpp">
39+
<ClCompile Include="generated_files\testRandom1\_testRandom1.cpp">
4040
<Filter>Generated Files</Filter>
4141
</ClCompile>
42-
<ClCompile Include="generated_files\testPredictable100000\_testPredictable100000.cpp">
42+
<ClCompile Include="generated_files\testRandom2\_testRandom2.cpp">
4343
<Filter>Generated Files</Filter>
4444
</ClCompile>
4545
<ClCompile Include="generated_files\testSequential10MB\_testSequential10MB.cpp">
4646
<Filter>Generated Files</Filter>
4747
</ClCompile>
48-
<ClCompile Include="generated_files\testText100000\_testText100000.cpp">
48+
<ClCompile Include="generated_files\testText10\_testText10.cpp">
4949
<Filter>Generated Files</Filter>
5050
</ClCompile>
51-
<ClCompile Include="generated_files\testSmall10\_testSmall10.cpp">
51+
<ClCompile Include="generated_files\testText1000\_testText1000.cpp">
5252
<Filter>Generated Files</Filter>
5353
</ClCompile>
54-
<ClCompile Include="generated_files\testPredictable1000\_testPredictable1000.cpp">
54+
<ClCompile Include="generated_files\testText100000\_testText100000.cpp">
5555
<Filter>Generated Files</Filter>
5656
</ClCompile>
5757
</ItemGroup>
@@ -71,25 +71,25 @@
7171
<ClInclude Include="..\test\TestExtraction.h">
7272
<Filter>Tests</Filter>
7373
</ClInclude>
74-
<ClInclude Include="generated_files\testRandom100000\_testRandom100000.h">
74+
<ClInclude Include="generated_files\testHtml100000\_testHtml100000.h">
7575
<Filter>Generated Files</Filter>
7676
</ClInclude>
77-
<ClInclude Include="generated_files\testHtml100000\_testHtml100000.h">
77+
<ClInclude Include="generated_files\testRandom1\_testRandom1.h">
7878
<Filter>Generated Files</Filter>
7979
</ClInclude>
80-
<ClInclude Include="generated_files\testPredictable100000\_testPredictable100000.h">
80+
<ClInclude Include="generated_files\testRandom2\_testRandom2.h">
8181
<Filter>Generated Files</Filter>
8282
</ClInclude>
8383
<ClInclude Include="generated_files\testSequential10MB\_testSequential10MB.h">
8484
<Filter>Generated Files</Filter>
8585
</ClInclude>
86-
<ClInclude Include="generated_files\testText100000\_testText100000.h">
86+
<ClInclude Include="generated_files\testText10\_testText10.h">
8787
<Filter>Generated Files</Filter>
8888
</ClInclude>
89-
<ClInclude Include="generated_files\testSmall10\_testSmall10.h">
89+
<ClInclude Include="generated_files\testText1000\_testText1000.h">
9090
<Filter>Generated Files</Filter>
9191
</ClInclude>
92-
<ClInclude Include="generated_files\testPredictable1000\_testPredictable1000.h">
92+
<ClInclude Include="generated_files\testText100000\_testText100000.h">
9393
<Filter>Generated Files</Filter>
9494
</ClInclude>
9595
</ItemGroup>

msvc/generate_test_files.bat

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
@echo off
22

3-
set TEST_NAME=testSmall10
3+
set TEST_NAME=testText10
44
set OUTDIR=.\generated_files\%TEST_NAME%
55
mkdir %OUTDIR% 1>NUL 2>NUL
66
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=10 --fill=text
77
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
88

9-
set TEST_NAME=testPredictable1000
9+
set TEST_NAME=testText1000
1010
set OUTDIR=.\generated_files\%TEST_NAME%
1111
mkdir %OUTDIR% 1>NUL 2>NUL
12-
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=10 --fill=text
12+
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=1000 --fill=text
1313
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
1414

15-
set TEST_NAME=testRandom100000
15+
set TEST_NAME=testText100000
1616
set OUTDIR=.\generated_files\%TEST_NAME%
1717
mkdir %OUTDIR% 1>NUL 2>NUL
18-
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=random
18+
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=text
1919
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
2020

21-
set TEST_NAME=testPredictable100000
21+
set TEST_NAME=testRandom1
2222
set OUTDIR=.\generated_files\%TEST_NAME%
2323
mkdir %OUTDIR% 1>NUL 2>NUL
24-
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=predictable
24+
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=random --seed=1
2525
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
2626

27-
set TEST_NAME=testHtml100000
27+
set TEST_NAME=testRandom2
2828
set OUTDIR=.\generated_files\%TEST_NAME%
2929
mkdir %OUTDIR% 1>NUL 2>NUL
30-
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=html
30+
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=random --seed=2
3131
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
3232

33-
set TEST_NAME=testText100000
33+
set TEST_NAME=testHtml100000
3434
set OUTDIR=.\generated_files\%TEST_NAME%
3535
mkdir %OUTDIR% 1>NUL 2>NUL
36-
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=text
36+
testfilegenerator.exe --file=%OUTDIR%\%TEST_NAME%.bin --size=100000 --fill=html
3737
bin2cpp.exe %OUTDIR%\%TEST_NAME%.bin %OUTDIR% _%TEST_NAME%.h %TEST_NAME% 450 -override
3838

3939
set TEST_NAME=testSequential10MB

test/TestExtraction.cpp

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,37 @@
22
#include "gtesthelper.h"
33

44
#include "generated_files\testHtml100000\_testHtml100000.h"
5-
#include "generated_files\testPredictable100000\_testPredictable100000.h"
6-
#include "generated_files\testRandom100000\_testRandom100000.h"
5+
#include "generated_files\testRandom1\_testRandom1.h"
6+
#include "generated_files\testRandom2\_testRandom2.h"
77
#include "generated_files\testSequential10MB\_testSequential10MB.h"
8+
#include "generated_files\testText10\_testText10.h"
9+
#include "generated_files\testText1000\_testText1000.h"
810
#include "generated_files\testText100000\_testText100000.h"
9-
#include "generated_files\testSmall10\_testSmall10.h"
1011

1112
gTestHelper & hlp = gTestHelper::getInstance();
1213

14+
std::string getExpectedFilePath()
15+
{
16+
std::string file;
17+
file.append("generated_files\\");
18+
file.append(hlp.getTestCaseName());
19+
file.append("\\");
20+
file.append(hlp.getTestCaseName());
21+
file.append(".bin");
22+
return file;
23+
}
24+
25+
std::string getActualFilePath()
26+
{
27+
std::string file;
28+
file.append("generated_files\\");
29+
file.append(hlp.getTestCaseName());
30+
file.append("\\");
31+
file.append(hlp.getTestCaseName());
32+
file.append(".output");
33+
return file;
34+
}
35+
1336
void TestExtraction::SetUp()
1437
{
1538
}
@@ -18,92 +41,107 @@ void TestExtraction::TearDown()
1841
{
1942
}
2043

21-
TEST_F(TestExtraction, testSmall10)
44+
TEST_F(TestExtraction, testText10)
2245
{
23-
static const char * expectedFilePath = "generated_files\\testSmall10\\testSmall10.bin";
24-
static const char * outputFilePath = "generated_files\\testSmall10\\testSmall10.output";
46+
static const std::string expectedFilePath = getExpectedFilePath();
47+
static const std::string outputFilePath = getActualFilePath();
2548

26-
const bin2cpp::File & file = bin2cpp::getTestSmall10File();
27-
bool extractSuccess = file.save(outputFilePath);
49+
const bin2cpp::File & file = bin2cpp::getTestText10File();
50+
bool extractSuccess = file.save(outputFilePath.c_str());
2851
ASSERT_TRUE(extractSuccess);
2952

3053
//assert content is the same
3154
std::string reason;
32-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
55+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
3356
ASSERT_TRUE(equal) << reason.c_str();
3457
}
3558

36-
TEST_F(TestExtraction, testHtml100000)
59+
TEST_F(TestExtraction, testText1000)
3760
{
38-
static const char * expectedFilePath = "generated_files\\testHtml100000\\testHtml100000.bin";
39-
static const char * outputFilePath = "generated_files\\testHtml100000\\testHtml100000.output";
61+
static const std::string expectedFilePath = getExpectedFilePath();
62+
static const std::string outputFilePath = getActualFilePath();
4063

41-
const bin2cpp::File & file = bin2cpp::getTestHtml100000File();
42-
bool extractSuccess = file.save(outputFilePath);
64+
const bin2cpp::File & file = bin2cpp::getTestText1000File();
65+
bool extractSuccess = file.save(outputFilePath.c_str());
4366
ASSERT_TRUE(extractSuccess);
4467

4568
//assert content is the same
4669
std::string reason;
47-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
70+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
4871
ASSERT_TRUE(equal) << reason.c_str();
4972
}
5073

51-
TEST_F(TestExtraction, testPredictable100000)
74+
TEST_F(TestExtraction, testText100000)
5275
{
53-
static const char * expectedFilePath = "generated_files\\testPredictable100000\\testPredictable100000.bin";
54-
static const char * outputFilePath = "generated_files\\testPredictable100000\\testPredictable100000.output";
76+
static const std::string expectedFilePath = getExpectedFilePath();
77+
static const std::string outputFilePath = getActualFilePath();
5578

56-
const bin2cpp::File & file = bin2cpp::getTestPredictable100000File();
57-
bool extractSuccess = file.save(outputFilePath);
79+
const bin2cpp::File & file = bin2cpp::getTestText100000File();
80+
bool extractSuccess = file.save(outputFilePath.c_str());
5881
ASSERT_TRUE(extractSuccess);
5982

6083
//assert content is the same
6184
std::string reason;
62-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
85+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
6386
ASSERT_TRUE(equal) << reason.c_str();
6487
}
6588

66-
TEST_F(TestExtraction, testRandom100000)
89+
TEST_F(TestExtraction, testHtml100000)
6790
{
68-
static const char * expectedFilePath = "generated_files\\testRandom100000\\testRandom100000.bin";
69-
static const char * outputFilePath = "generated_files\\testRandom100000\\testRandom100000.output";
91+
static const std::string expectedFilePath = getExpectedFilePath();
92+
static const std::string outputFilePath = getActualFilePath();
7093

71-
const bin2cpp::File & file = bin2cpp::getTestRandom100000File();
72-
bool extractSuccess = file.save(outputFilePath);
94+
const bin2cpp::File & file = bin2cpp::getTestHtml100000File();
95+
bool extractSuccess = file.save(outputFilePath.c_str());
7396
ASSERT_TRUE(extractSuccess);
7497

7598
//assert content is the same
7699
std::string reason;
77-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
100+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
78101
ASSERT_TRUE(equal) << reason.c_str();
79102
}
80103

81-
TEST_F(TestExtraction, testSequential10MB)
104+
TEST_F(TestExtraction, testRandom1)
82105
{
83-
static const char * expectedFilePath = "generated_files\\testSequential10MB\\testSequential10MB.bin";
84-
static const char * outputFilePath = "generated_files\\testSequential10MB\\testSequential10MB.output";
106+
static const std::string expectedFilePath = getExpectedFilePath();
107+
static const std::string outputFilePath = getActualFilePath();
85108

86-
const bin2cpp::File & file = bin2cpp::getTestSequential10MBFile();
87-
bool extractSuccess = file.save(outputFilePath);
109+
const bin2cpp::File & file = bin2cpp::getTestRandom1File();
110+
bool extractSuccess = file.save(outputFilePath.c_str());
88111
ASSERT_TRUE(extractSuccess);
89112

90113
//assert content is the same
91114
std::string reason;
92-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
115+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
93116
ASSERT_TRUE(equal) << reason.c_str();
94117
}
95118

96-
TEST_F(TestExtraction, testText100000)
119+
TEST_F(TestExtraction, testRandom2)
97120
{
98-
static const char * expectedFilePath = "generated_files\\testText100000\\testText100000.bin";
99-
static const char * outputFilePath = "generated_files\\testText100000\\testText100000.output";
121+
static const std::string expectedFilePath = getExpectedFilePath();
122+
static const std::string outputFilePath = getActualFilePath();
100123

101-
const bin2cpp::File & file = bin2cpp::getTestText100000File();
102-
bool extractSuccess = file.save(outputFilePath);
124+
const bin2cpp::File & file = bin2cpp::getTestRandom2File();
125+
bool extractSuccess = file.save(outputFilePath.c_str());
126+
ASSERT_TRUE(extractSuccess);
127+
128+
//assert content is the same
129+
std::string reason;
130+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
131+
ASSERT_TRUE(equal) << reason.c_str();
132+
}
133+
134+
TEST_F(TestExtraction, testSequential10MB)
135+
{
136+
static const std::string expectedFilePath = getExpectedFilePath();
137+
static const std::string outputFilePath = getActualFilePath();
138+
139+
const bin2cpp::File & file = bin2cpp::getTestSequential10MBFile();
140+
bool extractSuccess = file.save(outputFilePath.c_str());
103141
ASSERT_TRUE(extractSuccess);
104142

105143
//assert content is the same
106144
std::string reason;
107-
bool equal = hlp.isFileEquals(expectedFilePath, outputFilePath, reason);
145+
bool equal = hlp.isFileEquals(expectedFilePath.c_str(), outputFilePath.c_str(), reason);
108146
ASSERT_TRUE(equal) << reason.c_str();
109147
}

0 commit comments

Comments
 (0)