diff options
| Commit | fa077610dfe8b59eb2af069d2f3e92b4790a21d2 (patch) | |
|---|---|---|
| Author | 2018-11-13 20:24:04 +0200 | |
| Committer | 2018-11-13 20:24:04 +0200 | |
| Files | aa0cb327bdcf26a50b0ff39849244d49f1e4bbf8 /JSImpl | |
| IPL-fa077610dfe8b59eb2af069d2f3e92b4790a21d2.tar IPL-fa077610dfe8b59eb2af069d2f3e92b4790a21d2.tar.gz IPL-fa077610dfe8b59eb2af069d2f3e92b4790a21d2.zip | ||
| Parent | 7f2b2038c600f5a482ee84b04b922637f757c649 (diff) | |
Added tests for sprt
4 files changed, 70 insertions, 8 deletions
| -rw-r--r-- | JSImpl/test/Test.make | 14 | ||||
| -rw-r--r-- | JSImpl/test/Test.vcxproj | 15 | ||||
| -rw-r--r-- | JSImpl/test/Test.vcxproj.filters | 1 | ||||
| -rw-r--r-- | JSImpl/test/sprtTests.cpp | 48 |
diff --git a/JSImpl/test/Test.make b/JSImpl/test/Test.make index 4836496..4540d2d 100644 --- a/JSImpl/test/Test.make +++ b/JSImpl/test/Test.make @@ -47,7 +47,7 @@ ifeq ($(config),debug64) TARGETDIR = ../build/bin/Debug TARGET = $(TARGETDIR)/Test DEFINES += -D_SCL_SECURE_NO_WARNINGS - INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." + INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 @@ -56,7 +56,7 @@ ifeq ($(config),debug64) ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -L"../build/bin/Debug" -L"." -m64 - LDDEPS += ../build/bin/Debug/libJSLib.a ../build/bin/Debug/libgtest.a ../build/bin/Debug/libgmock.a ../build/bin/Debug/libgtest_main.a + LDDEPS += ../build/bin/Debug/libsprt.a ../build/bin/Debug/libJSLib.a ../build/bin/Debug/libgtest.a ../build/bin/Debug/libgmock.a ../build/bin/Debug/libgtest_main.a LIBS += $(LDDEPS) -lpthread EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) @@ -65,6 +65,7 @@ ifeq ($(config),debug64) $(OBJDIR)/LexerTests.o \ $(OBJDIR)/ParserTests.o \ $(OBJDIR)/empty.o \ + $(OBJDIR)/sprtTests.o \ define PREBUILDCMDS endef @@ -79,7 +80,7 @@ ifeq ($(config),release64) TARGETDIR = ../build/bin/Release TARGET = $(TARGETDIR)/Test DEFINES += -D_SCL_SECURE_NO_WARNINGS - INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." + INCLUDES += -I"googletest/googletest/include" -I"googletest/googlemock/include" -I".." -I"../../spasm/src" ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES) ALL_ASMFLAGS += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 @@ -88,7 +89,7 @@ ifeq ($(config),release64) ALL_OBJCPPFLAGS += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -Werror -Wall -Wextra -g -O3 -m64 -std=c++14 ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES) ALL_LDFLAGS += $(LDFLAGS) -L"../build/bin/Release" -L"." -m64 - LDDEPS += ../build/bin/Release/libJSLib.a ../build/bin/Release/libgtest.a ../build/bin/Release/libgmock.a ../build/bin/Release/libgtest_main.a + LDDEPS += ../build/bin/Release/libsprt.a ../build/bin/Release/libJSLib.a ../build/bin/Release/libgtest.a ../build/bin/Release/libgmock.a ../build/bin/Release/libgtest_main.a LIBS += $(LDDEPS) -lpthread EXTERNAL_LIBS += LINKOBJS = $(OBJECTS) @@ -97,6 +98,7 @@ ifeq ($(config),release64) $(OBJDIR)/LexerTests.o \ $(OBJDIR)/ParserTests.o \ $(OBJDIR)/empty.o \ + $(OBJDIR)/sprtTests.o \ define PREBUILDCMDS endef @@ -168,6 +170,10 @@ $(OBJDIR)/empty.o: empty.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/. @echo $(notdir $<) $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" +$(OBJDIR)/sprtTests.o: sprtTests.cpp $(GCH) $(MAKEFILE) | $(OBJDIR)/. + @echo $(notdir $<) + $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -c "$<" + -include $(OBJECTS:%.o=%.d) ifneq (,$(PCH)) -include $(OBJDIR)/$(notdir $(PCH)).d diff --git a/JSImpl/test/Test.vcxproj b/JSImpl/test/Test.vcxproj index 6bf7d68..3a7058a 100644 --- a/JSImpl/test/Test.vcxproj +++ b/JSImpl/test/Test.vcxproj @@ -21,11 +21,13 @@ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
+ <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -55,7 +57,7 @@ <ClCompile>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -70,7 +72,7 @@ </ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -85,7 +87,7 @@ <ClCompile>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<StringPooling>true</StringPooling>
@@ -100,7 +102,7 @@ </ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -120,8 +122,13 @@ </ClCompile>
<ClCompile Include="ParserTests.cpp">
</ClCompile>
+ <ClCompile Include="sprtTests.cpp">
+ </ClCompile>
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\..\spasm\solution\sprt.vcxproj">
+ <Project>{AE0A9E7C-9A41-9F0D-432E-85102F441B0F}</Project>
+ </ProjectReference>
<ProjectReference Include="..\solution\JSLib.vcxproj">
<Project>{19EA680D-85FE-90BE-4E80-341EBA538DEF}</Project>
</ProjectReference>
diff --git a/JSImpl/test/Test.vcxproj.filters b/JSImpl/test/Test.vcxproj.filters index e1968c9..b7e0456 100644 --- a/JSImpl/test/Test.vcxproj.filters +++ b/JSImpl/test/Test.vcxproj.filters @@ -4,5 +4,6 @@ <ClCompile Include="empty.cpp" />
<ClCompile Include="LexerTests.cpp" />
<ClCompile Include="ParserTests.cpp" />
+ <ClCompile Include="sprtTests.cpp" />
</ItemGroup>
</Project>
diff --git a/JSImpl/test/sprtTests.cpp b/JSImpl/test/sprtTests.cpp new file mode 100644 index 0000000..92bd5a6 --- /dev/null +++ b/JSImpl/test/sprtTests.cpp @@ -0,0 +1,48 @@ +#include <gtest/gtest.h> + +#include <spasm.hpp> +#include <sstream> + +using Spasm::OpCodes; + +struct SPRTTest : public ::testing::Test +{ + void Run(Spasm::byte bytecode[], size_t size) + { + VM.Initialize(size, bytecode, Input, Output); + ASSERT_EQ(Spasm::Spasm::RunResult::Success, VM.run()); + } + Spasm::Spasm VM; + std::istringstream Input; + std::ostringstream Output; +}; + +TEST_F(SPRTTest, Empty) +{ +} + +TEST_F(SPRTTest, Mutliply) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::Mul, 3, 1, 2, + OpCodes::Print, 3, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "42"); +} + +TEST_F(SPRTTest, Less) +{ + Spasm::byte bytecode[] = { + OpCodes::Const, 1, 6, + OpCodes::Const, 2, 7, + OpCodes::Less, 3, 1, 2, + OpCodes::Print, 3, + }; + + Run(bytecode, sizeof(bytecode)); + ASSERT_EQ(Output.str(), "1"); +} |
