From fa077610dfe8b59eb2af069d2f3e92b4790a21d2 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Tue, 13 Nov 2018 20:24:04 +0200 Subject: Added tests for sprt --- JSImpl/test/Test.make | 14 ++++++++---- JSImpl/test/Test.vcxproj | 15 +++++++++---- JSImpl/test/Test.vcxproj.filters | 1 + JSImpl/test/sprtTests.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 JSImpl/test/sprtTests.cpp (limited to 'JSImpl') 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 @@ Application true v140 + x64 Application false v140 + x64 @@ -55,7 +57,7 @@ %(AdditionalOptions) Disabled - googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories) + googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories) _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false EnableFastChecks @@ -70,7 +72,7 @@ _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories) + googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories) Console @@ -85,7 +87,7 @@ %(AdditionalOptions) MaxSpeed - googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories) + googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories) _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) false true @@ -100,7 +102,7 @@ _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - googletest\googletest\include;googletest\googlemock\include;..;%(AdditionalIncludeDirectories) + googletest\googletest\include;googletest\googlemock\include;..;..\..\spasm\src;%(AdditionalIncludeDirectories) Console @@ -120,8 +122,13 @@ + + + + {AE0A9E7C-9A41-9F0D-432E-85102F441B0F} + {19EA680D-85FE-90BE-4E80-341EBA538DEF} 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 @@ + 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 + +#include +#include + +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"); +} -- cgit v1.3.1-23-gd82d