mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added Unit Test for the HashTable example
This commit is contained in:
		
							
								
								
									
										22
									
								
								tests/ArduinoJsonParserTests.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								tests/ArduinoJsonParserTests.sln
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  |  | ||||||
|  | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||||
|  | # Visual Studio 2013 | ||||||
|  | VisualStudioVersion = 12.0.21005.1 | ||||||
|  | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
|  | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArduinoJsonParserTests", "ArduinoJsonParserTests.vcxproj", "{4DD596EF-0185-4AB4-A3C2-F20C496F7806}" | ||||||
|  | EndProject | ||||||
|  | Global | ||||||
|  | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||||
|  | 		Debug|Win32 = Debug|Win32 | ||||||
|  | 		Release|Win32 = Release|Win32 | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||||
|  | 		{4DD596EF-0185-4AB4-A3C2-F20C496F7806}.Debug|Win32.ActiveCfg = Debug|Win32 | ||||||
|  | 		{4DD596EF-0185-4AB4-A3C2-F20C496F7806}.Debug|Win32.Build.0 = Debug|Win32 | ||||||
|  | 		{4DD596EF-0185-4AB4-A3C2-F20C496F7806}.Release|Win32.ActiveCfg = Release|Win32 | ||||||
|  | 		{4DD596EF-0185-4AB4-A3C2-F20C496F7806}.Release|Win32.Build.0 = Release|Win32 | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(SolutionProperties) = preSolution | ||||||
|  | 		HideSolutionNode = FALSE | ||||||
|  | 	EndGlobalSection | ||||||
|  | EndGlobal | ||||||
							
								
								
									
										103
									
								
								tests/ArduinoJsonParserTests.vcxproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								tests/ArduinoJsonParserTests.vcxproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <ItemGroup Label="ProjectConfigurations"> | ||||||
|  |     <ProjectConfiguration Include="Debug|Win32"> | ||||||
|  |       <Configuration>Debug</Configuration> | ||||||
|  |       <Platform>Win32</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |     <ProjectConfiguration Include="Release|Win32"> | ||||||
|  |       <Configuration>Release</Configuration> | ||||||
|  |       <Platform>Win32</Platform> | ||||||
|  |     </ProjectConfiguration> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <PropertyGroup Label="Globals"> | ||||||
|  |     <ProjectGuid>{4DD596EF-0185-4AB4-A3C2-F20C496F7806}</ProjectGuid> | ||||||
|  |     <Keyword>Win32Proj</Keyword> | ||||||
|  |     <RootNamespace>ArduinoJsonParserTests</RootNamespace> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>DynamicLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v120</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |     <UseOfMfc>false</UseOfMfc> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>DynamicLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v120</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |     <UseOfMfc>false</UseOfMfc> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||||||
|  |   <ImportGroup Label="ExtensionSettings"> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||||||
|  |   </ImportGroup> | ||||||
|  |   <PropertyGroup Label="UserMacros" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <LinkIncremental>true</LinkIncremental> | ||||||
|  |     <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..</IncludePath> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <LinkIncremental>true</LinkIncremental> | ||||||
|  |     <IncludePath>$(VC_IncludePath);..</IncludePath> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <PrecompiledHeader>NotUsing</PrecompiledHeader> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <Optimization>Disabled</Optimization> | ||||||
|  |       <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||||||
|  |       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <UseFullPaths>true</UseFullPaths> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Windows</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |       <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <PrecompiledHeader>Use</PrecompiledHeader> | ||||||
|  |       <Optimization>MaxSpeed</Optimization> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||||||
|  |       <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <UseFullPaths>true</UseFullPaths> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Windows</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="..\JsonArray.h" /> | ||||||
|  |     <ClInclude Include="..\JsonHashTable.h" /> | ||||||
|  |     <ClInclude Include="..\JsonObjectBase.h" /> | ||||||
|  |     <ClInclude Include="..\JsonParser.h" /> | ||||||
|  |     <ClInclude Include="..\utility\jsmn.h" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="..\JsonArray.cpp" /> | ||||||
|  |     <ClCompile Include="..\JsonHashTable.cpp" /> | ||||||
|  |     <ClCompile Include="..\JsonObjectBase.cpp" /> | ||||||
|  |     <ClCompile Include="..\utility\jsmn.cpp" /> | ||||||
|  |     <ClCompile Include="TestHashTableExample.cpp" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||||
|  |   <ImportGroup Label="ExtensionTargets"> | ||||||
|  |   </ImportGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										51
									
								
								tests/ArduinoJsonParserTests.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								tests/ArduinoJsonParserTests.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Filter Include="Source Files"> | ||||||
|  |       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||||||
|  |       <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Header Files"> | ||||||
|  |       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||||||
|  |       <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Resource Files"> | ||||||
|  |       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||||||
|  |       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="..\JsonArray.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="..\JsonHashTable.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="..\JsonObjectBase.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="..\JsonParser.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="..\utility\jsmn.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="..\JsonArray.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="..\JsonHashTable.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="..\JsonObjectBase.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="..\utility\jsmn.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="TestHashTableExample.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |   </ItemGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										61
									
								
								tests/TestHashTableExample.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								tests/TestHashTableExample.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | |||||||
|  | #include "CppUnitTest.h" | ||||||
|  | #include "JsonParser.h" | ||||||
|  | #include <string> | ||||||
|  |  | ||||||
|  | using namespace std; | ||||||
|  | using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||||
|  |  | ||||||
|  | namespace ArduinoJsonParserTests | ||||||
|  | {		 | ||||||
|  | 	TEST_CLASS(TestHashTableExample) | ||||||
|  | 	{ | ||||||
|  | 		char json[128]; | ||||||
|  | 		JsonParser<32> parser; | ||||||
|  | 		JsonHashTable hashTable; | ||||||
|  |  | ||||||
|  | 	public: | ||||||
|  |  | ||||||
|  | 		TEST_METHOD_INITIALIZE(Initialize) | ||||||
|  | 		{ | ||||||
|  | 			strcpy(json, "{\"Name\":\"Blanchon\",\"Skills\":[\"C\",\"C++\",\"C#\"],\"Age\":32,\"Online\":true}"); | ||||||
|  | 			hashTable = parser.parseHashTable(json); | ||||||
|  | 		} | ||||||
|  | 						 | ||||||
|  | 		TEST_METHOD(HashTable_Success_ReturnsTrue) | ||||||
|  | 		{ | ||||||
|  | 			Assert::IsTrue(hashTable.success()); | ||||||
|  | 		}			 | ||||||
|  |  | ||||||
|  | 		TEST_METHOD(HashTable_GetString_ReturnsExpectedValue) | ||||||
|  | 		{ | ||||||
|  | 			string name = hashTable.getString("Name"); | ||||||
|  | 			Assert::AreEqual(name, string("Blanchon")); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		TEST_METHOD(HashTable_GetArray_ReturnsExpectedValue) | ||||||
|  | 		{ | ||||||
|  | 			JsonArray skills = hashTable.getArray("Skills"); | ||||||
|  |  | ||||||
|  | 			string skill0 = skills.getString(0); | ||||||
|  | 			Assert::AreEqual(skill0, string("C")); | ||||||
|  |  | ||||||
|  | 			string skill1 = skills.getString(1); | ||||||
|  | 			Assert::AreEqual(skill1, string("C++")); | ||||||
|  |  | ||||||
|  | 			string skill2 = skills.getString(2); | ||||||
|  | 			Assert::AreEqual(skill2, string("C#")); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		TEST_METHOD(HashTable_GetLong_ReturnsExpectedValue) | ||||||
|  | 		{ | ||||||
|  | 			int age = hashTable.getLong("Age"); | ||||||
|  | 			Assert::AreEqual(32, age); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		TEST_METHOD(HashTable_GetBool_ReturnsExpectedValue) | ||||||
|  | 		{ | ||||||
|  | 			bool online = hashTable.getBool("Online"); | ||||||
|  | 			Assert::AreEqual(true, online); | ||||||
|  | 		} | ||||||
|  | 	}; | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user