mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-16 11:35:44 +02:00
Added first yaml test
This commit is contained in:
@@ -16,7 +16,6 @@ Global
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x64.Build.0 = Debug|x64
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Debug|x86.Build.0 = Debug|Win32
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x64.ActiveCfg = Release|x64
|
||||
@@ -24,6 +23,7 @@ Global
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x86.ActiveCfg = Release|Win32
|
||||
{11C8A44F-A303-4885-B5AD-5B65F7FE41C0}.Release|x86.Build.0 = Release|Win32
|
||||
{33ECE513-60D1-4949-A4A9-C95D353C2CF0}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{33ECE513-60D1-4949-A4A9-C95D353C2CF0}.Debug|x64.Build.0 = Debug|Win32
|
||||
{33ECE513-60D1-4949-A4A9-C95D353C2CF0}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{33ECE513-60D1-4949-A4A9-C95D353C2CF0}.Debug|x86.Build.0 = Debug|Win32
|
||||
{33ECE513-60D1-4949-A4A9-C95D353C2CF0}.Release|x64.ActiveCfg = Release|x64
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <stack>
|
||||
#include <cstring>
|
||||
#include <IPAddress.h>
|
||||
|
||||
namespace Configuration {
|
||||
class Parser : public Tokenizer {
|
||||
|
@@ -80,11 +80,9 @@ namespace Configuration {
|
||||
int indent_;
|
||||
|
||||
TokenKind kind_;
|
||||
union {
|
||||
struct {
|
||||
const char* sValueStart_;
|
||||
const char* sValueEnd_;
|
||||
};
|
||||
struct {
|
||||
const char* sValueStart_;
|
||||
const char* sValueEnd_;
|
||||
};
|
||||
} token_;
|
||||
|
||||
|
@@ -20,11 +20,7 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifndef ESP32
|
||||
# include <string>
|
||||
#else
|
||||
# include "WString.h"
|
||||
#endif
|
||||
#include "WString.h"
|
||||
|
||||
class StringRange {
|
||||
const char* start_;
|
||||
@@ -104,7 +100,7 @@ public:
|
||||
|
||||
inline bool isFloat(float& floatval) {
|
||||
char* floatEnd;
|
||||
floatval = strtod(start_, &floatEnd);
|
||||
floatval = float(strtod(start_, &floatEnd));
|
||||
return floatEnd == end_;
|
||||
}
|
||||
};
|
||||
|
56
Grbl_Esp32/test/Configuration/YamlParser.cpp
Normal file
56
Grbl_Esp32/test/Configuration/YamlParser.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "../TestFramework.h"
|
||||
|
||||
#include <src/Configuration/Tokenizer.h>
|
||||
#include <src/Configuration/Parser.h>
|
||||
|
||||
namespace Configuration {
|
||||
Test(YamlParser, BasicProperties) {
|
||||
const char* config =
|
||||
"a: aap\n"
|
||||
"b: banaan\n"
|
||||
"\n"
|
||||
"c: chocolade";
|
||||
|
||||
Parser p(config, config + strlen(config));
|
||||
{
|
||||
Assert(p.key().equals("a"), "Expected 'a'");
|
||||
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
|
||||
}
|
||||
|
||||
Assert(p.moveNext(), "Move next failed.");
|
||||
{
|
||||
Assert(p.key().equals("b"), "Expected 'b'");
|
||||
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
|
||||
}
|
||||
|
||||
Assert(p.moveNext(), "Move next failed.");
|
||||
{
|
||||
Assert(p.key().equals("c"), "Expected 'c'");
|
||||
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
|
||||
}
|
||||
Assert(!p.moveNext(), "Move next failed.");
|
||||
}
|
||||
|
||||
Test(YamlParser, SimpleSection) {
|
||||
const char* config = "a: aap\nb: banaan\n\nc: chocolade";
|
||||
Parser p(config, config + strlen(config));
|
||||
{
|
||||
Assert(p.key().equals("a"), "Expected 'a'");
|
||||
Assert(p.stringValue().equals("aap"), "Expected 'aap'");
|
||||
}
|
||||
|
||||
Assert(p.moveNext(), "Move next failed.");
|
||||
{
|
||||
Assert(p.key().equals("b"), "Expected 'b'");
|
||||
Assert(p.stringValue().equals("banaan"), "Expected 'banaan'");
|
||||
}
|
||||
|
||||
Assert(p.moveNext(), "Move next failed.");
|
||||
{
|
||||
Assert(p.key().equals("c"), "Expected 'c'");
|
||||
Assert(p.stringValue().equals("chocolade"), "Expected 'chocolade'");
|
||||
}
|
||||
Assert(!p.moveNext(), "Move next failed.");
|
||||
}
|
||||
|
||||
}
|
@@ -33,12 +33,17 @@
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<None Include="Grbl_Esp32\src\Configuration\Parser.md" />
|
||||
<None Include="Grbl_Esp32\src\StackTrace\debug_helpers_asm.S" />
|
||||
<None Include="Grbl_Esp32\test\UnitTests.md" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Grbl_Esp32\src\Assert.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\Parser.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\ParserHandler.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\Tokenizer.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\TokenKind.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Pin.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Pins\ErrorPinDetail.h" />
|
||||
<ClInclude Include="Grbl_Esp32\src\Pins\GPIOPinDetail.h" />
|
||||
@@ -53,10 +58,13 @@
|
||||
<ClInclude Include="Grbl_Esp32\test\TestFactory.h" />
|
||||
<ClInclude Include="Grbl_Esp32\test\TestFramework.h" />
|
||||
<ClInclude Include="X86TestSupport\Arduino.h" />
|
||||
<ClInclude Include="X86TestSupport\IPAddress.h" />
|
||||
<ClInclude Include="X86TestSupport\SoftwareGPIO.h" />
|
||||
<ClInclude Include="X86TestSupport\WString.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Grbl_Esp32\src\Configuration\Parser.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\Configuration\Tokenizer.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\Pin.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\Pins\ErrorPinDetail.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\Pins\GPIOPinDetail.cpp" />
|
||||
@@ -68,6 +76,7 @@
|
||||
<ClCompile Include="Grbl_Esp32\src\Pins\VoidPinDetail.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\StackTrace\AssertionFailed.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\src\StackTrace\debug_helpers.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\test\Configuration\YamlParser.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\test\Pins\BasicGPIO.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\test\Pins\Error.cpp" />
|
||||
<ClCompile Include="Grbl_Esp32\test\Pins\GPIO.cpp" />
|
||||
|
@@ -19,6 +19,12 @@
|
||||
<Filter Include="X86TestSupport">
|
||||
<UniqueIdentifier>{a166a529-634f-48dc-b368-6c03f6f0a36f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="test\Configuration">
|
||||
<UniqueIdentifier>{6ae3ae24-fdcd-49f4-9797-a0b0f973c2dc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="src\Configuration">
|
||||
<UniqueIdentifier>{2b406c50-ba04-4c6d-a21e-0daedeeda9d9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Grbl_Esp32\test\TestFramework.h">
|
||||
@@ -72,6 +78,21 @@
|
||||
<ClInclude Include="Grbl_Esp32\src\Pins\I2SOPinDetail.h">
|
||||
<Filter>src\Pins</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\Parser.h">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\ParserHandler.h">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\Tokenizer.h">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Grbl_Esp32\src\Configuration\TokenKind.h">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="X86TestSupport\IPAddress.h">
|
||||
<Filter>X86TestSupport</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Grbl_Esp32\test\TestFrameworkTest.cpp">
|
||||
@@ -140,6 +161,15 @@
|
||||
<ClCompile Include="Grbl_Esp32\src\Pins\I2SOPinDetail.cpp">
|
||||
<Filter>src\Pins</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Grbl_Esp32\test\Configuration\YamlParser.cpp">
|
||||
<Filter>test\Configuration</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Grbl_Esp32\src\Configuration\Tokenizer.cpp">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Grbl_Esp32\src\Configuration\Parser.cpp">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Grbl_Esp32\test\UnitTests.md">
|
||||
@@ -149,5 +179,8 @@
|
||||
<Filter>src\StackTrace</Filter>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Grbl_Esp32\src\Configuration\Parser.md">
|
||||
<Filter>src\Configuration</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
52
X86TestSupport/IPAddress.h
Normal file
52
X86TestSupport/IPAddress.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "WString.h"
|
||||
|
||||
class IPAddress {
|
||||
private:
|
||||
union {
|
||||
uint8_t bytes[4]; // IPv4 address
|
||||
uint32_t dword;
|
||||
} _address;
|
||||
|
||||
// Access the raw byte array containing the address. Because this returns a pointer
|
||||
// to the internal structure rather than a copy of the address this function should only
|
||||
// be used when you know that the usage of the returned uint8_t* will be transient and not
|
||||
// stored.
|
||||
uint8_t* raw_address() { return _address.bytes; }
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
IPAddress() { _address.dword = 0; }
|
||||
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) {
|
||||
_address.bytes[0] = first_octet;
|
||||
_address.bytes[1] = second_octet;
|
||||
_address.bytes[2] = third_octet;
|
||||
_address.bytes[3] = fourth_octet;
|
||||
}
|
||||
IPAddress(uint32_t address) { _address.dword = address; }
|
||||
IPAddress(const uint8_t* address) { memcpy(_address.bytes, address, 4); }
|
||||
virtual ~IPAddress() {}
|
||||
|
||||
bool fromString(const char* address) { throw "not implemented"; }
|
||||
bool fromString(const String& address) { return fromString(address.c_str()); }
|
||||
|
||||
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
|
||||
// to a four-byte uint8_t array is expected
|
||||
operator uint32_t() const { return _address.dword; }
|
||||
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }
|
||||
bool operator==(const uint8_t* addr) const { return (*this) == IPAddress(addr); }
|
||||
|
||||
// Overloaded index operator to allow getting and setting individual octets of the address
|
||||
uint8_t operator[](int index) const { return _address.bytes[index]; }
|
||||
uint8_t& operator[](int index) { return _address.bytes[index]; }
|
||||
|
||||
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
|
||||
IPAddress& operator=(const uint8_t* address) { memcpy(_address.bytes, address, 4); }
|
||||
IPAddress& operator=(uint32_t address) { _address.dword = address; }
|
||||
|
||||
String toString() const { throw "not implemented"; }
|
||||
};
|
||||
|
||||
const IPAddress INADDR_NONE(0, 0, 0, 0);
|
Reference in New Issue
Block a user