Skip to content

Commit 8a5647e

Browse files
committed
Added TestNativeFunc unit tests to the project.
1 parent 995c48e commit 8a5647e

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@
3131
/build
3232
/msvc/TestFilesystemFunc.testGetFileSize
3333
/msvc/TestFilesystemFunc.testFileExists
34+
/msvc/TestFilesystemFunc.testGetFileModifiedDate.1.txt
35+
/msvc/TestFilesystemFunc.testGetFileModifiedDate.2.txt

msvc/bin2cpp_unittest.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<ClCompile Include="..\src\bin2cpp_unittest\TestEnvironmentFunc.cpp" />
112112
<ClCompile Include="..\src\bin2cpp_unittest\TestExtraction.cpp" />
113113
<ClCompile Include="..\src\bin2cpp_unittest\TestFilesystemFunc.cpp" />
114+
<ClCompile Include="..\src\bin2cpp_unittest\TestNativeFunc.cpp" />
114115
<ClCompile Include="..\src\bin2cpp_unittest\TestStringFunc.cpp" />
115116
<ClCompile Include="generated_files\testBaseClass\_testBaseClass.cpp" />
116117
<ClCompile Include="generated_files\testEncodingHex\_testEncodingHex.cpp" />
@@ -160,6 +161,7 @@
160161
<ClInclude Include="..\src\bin2cpp_unittest\TestEnvironmentFunc.h" />
161162
<ClInclude Include="..\src\bin2cpp_unittest\TestExtraction.h" />
162163
<ClInclude Include="..\src\bin2cpp_unittest\TestFilesystemFunc.h" />
164+
<ClInclude Include="..\src\bin2cpp_unittest\TestNativeFunc.h" />
163165
<ClInclude Include="..\src\bin2cpp_unittest\TestStringFunc.h" />
164166
<ClInclude Include="generated_files\testBaseClass\_testBaseClass.h" />
165167
<ClInclude Include="generated_files\testEncodingHex\_testEncodingHex.h" />

msvc/bin2cpp_unittest.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
<ClCompile Include="..\src\bin2cpp_unittest\TestStringFunc.cpp">
127127
<Filter>Tests</Filter>
128128
</ClCompile>
129+
<ClCompile Include="..\src\bin2cpp_unittest\TestNativeFunc.cpp">
130+
<Filter>Tests</Filter>
131+
</ClCompile>
129132
</ItemGroup>
130133
<ItemGroup>
131134
<None Include="bin2cppTest.x86.debug.xml">
@@ -236,6 +239,9 @@
236239
<ClInclude Include="..\src\bin2cpp_unittest\TestStringFunc.h">
237240
<Filter>Tests</Filter>
238241
</ClInclude>
242+
<ClInclude Include="..\src\bin2cpp_unittest\TestNativeFunc.h">
243+
<Filter>Tests</Filter>
244+
</ClInclude>
239245
</ItemGroup>
240246
<ItemGroup>
241247
<CustomBuild Include="generate_test_files.bat" />

src/bin2cpp_unittest/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ add_executable(bin2cpp_unittest
8484
TestEnvironmentFunc.h
8585
TestFilesystemFunc.cpp
8686
TestFilesystemFunc.h
87+
TestNativeFunc.cpp
88+
TestNativeFunc.h
8789
TestStringFunc.cpp
8890
TestStringFunc.h
8991
main.cpp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "TestNativeFunc.h"
2+
#include "nativefunc.h"
3+
#include <time.h>
4+
5+
using namespace nativefunc;
6+
7+
namespace nativefunc { namespace test
8+
{
9+
std::tm getLocalSystemTime()
10+
{
11+
time_t rawtime;
12+
struct tm * timeinfo;
13+
14+
time (&rawtime);
15+
timeinfo = localtime (&rawtime);
16+
17+
return (*timeinfo);
18+
}
19+
20+
//--------------------------------------------------------------------------------------------------
21+
void TestNativeFunc::SetUp()
22+
{
23+
}
24+
//--------------------------------------------------------------------------------------------------
25+
void TestNativeFunc::TearDown()
26+
{
27+
}
28+
//--------------------------------------------------------------------------------------------------
29+
TEST_F(TestNativeFunc, testMillisleep)
30+
{
31+
//assert that millisleep() is actually sleeping
32+
std::tm time1 = getLocalSystemTime();
33+
ASSERT_EQ(0, nativefunc::millisleep(5000 + 50)); //at least 5 seconds
34+
std::tm time2 = getLocalSystemTime();
35+
36+
//convert hour, minute and seconds to absolute seconds
37+
int seconds1 = time1.tm_hour*3600+time1.tm_min*60+time1.tm_sec;
38+
int seconds2 = time2.tm_hour*3600+time2.tm_min*60+time2.tm_sec;
39+
40+
static const int EXPECTED = 5;
41+
int diff = seconds2 - seconds1;
42+
43+
//assert near
44+
ASSERT_GT(diff, EXPECTED-1); //allow 1 seconds of difference
45+
ASSERT_LT(diff, EXPECTED+1); //allow 1 seconds of difference
46+
}
47+
//--------------------------------------------------------------------------------------------------
48+
} // End namespace test
49+
} // End namespace nativefunc
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef TESTNATIVEFUNC_H
2+
#define TESTNATIVEFUNC_H
3+
4+
#include <gtest/gtest.h>
5+
6+
namespace nativefunc { namespace test
7+
{
8+
class TestNativeFunc : public ::testing::Test
9+
{
10+
public:
11+
virtual void SetUp();
12+
virtual void TearDown();
13+
};
14+
15+
} // End namespace test
16+
} // End namespace nativefunc
17+
18+
#endif //TESTNATIVEFUNC_H

0 commit comments

Comments
 (0)