mirror of
https://github.com/alexhopeoconnor/DFTE.git
synced 2026-10-22 08:42:08 +10:00
Add DFTE sources and tests
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#include "test_utils.h"
|
||||
#include <unity.h>
|
||||
#include <pgmspace.h>
|
||||
|
||||
// Helper function to capture rendered output
|
||||
String captureRenderedOutput(TemplateContext& ctx, size_t bufferSize) {
|
||||
String output;
|
||||
uint8_t* buffer = new uint8_t[bufferSize];
|
||||
|
||||
if (!buffer) {
|
||||
return output;
|
||||
}
|
||||
|
||||
while (!TemplateRenderer::isComplete(ctx)) {
|
||||
size_t written = TemplateRenderer::renderNextChunk(ctx, buffer, bufferSize);
|
||||
if (written > 0) {
|
||||
// Arduino String doesn't have (const char*, size_t) constructor
|
||||
// Use substring approach or create temporary string
|
||||
char* temp = new char[written + 1];
|
||||
memcpy(temp, buffer, written);
|
||||
temp[written] = '\0';
|
||||
output += String(temp);
|
||||
delete[] temp;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
return output;
|
||||
}
|
||||
|
||||
// Helper function to compare rendered output
|
||||
bool compareRenderedOutput(const String& expected, TemplateContext& ctx, size_t bufferSize) {
|
||||
String actual = captureRenderedOutput(ctx, bufferSize);
|
||||
return actual == expected;
|
||||
}
|
||||
|
||||
// Note: For test RAM getters, define them as regular functions in test files
|
||||
// Example:
|
||||
// static String testData = "test";
|
||||
// const char* getTestData() { return testData.c_str(); }
|
||||
|
||||
// Helper function to verify template output
|
||||
void verifyTemplateOutput(const char* templateData, PlaceholderRegistry& registry, const String& expected) {
|
||||
TemplateContext ctx;
|
||||
ctx.setRegistry(®istry);
|
||||
TemplateRenderer::initializeContext(ctx, templateData);
|
||||
|
||||
String actual = captureRenderedOutput(ctx);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected.c_str(), actual.c_str(),
|
||||
"Template output should match expected");
|
||||
}
|
||||
|
||||
// Helper function to render template to string
|
||||
String renderTemplateToString(const char* templateData, PlaceholderRegistry& registry, size_t bufferSize) {
|
||||
TemplateContext ctx;
|
||||
ctx.setRegistry(®istry);
|
||||
TemplateRenderer::initializeContext(ctx, templateData);
|
||||
return captureRenderedOutput(ctx, bufferSize);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef TEST_UTILS_H
|
||||
#define TEST_UTILS_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <TemplateEngine.h>
|
||||
|
||||
// Test structure and state management
|
||||
using TestFn = void(*)();
|
||||
|
||||
struct TestCase {
|
||||
const char* name;
|
||||
TestFn fn;
|
||||
uint16_t line;
|
||||
};
|
||||
|
||||
#define TEST_ENTRY(fn) { #fn, fn, __LINE__ }
|
||||
|
||||
// Helper function to capture rendered output
|
||||
String captureRenderedOutput(TemplateContext& ctx, size_t bufferSize = 512);
|
||||
|
||||
// Helper function to compare rendered output
|
||||
bool compareRenderedOutput(const String& expected, TemplateContext& ctx, size_t bufferSize = 512);
|
||||
|
||||
// Helper function to create test RAM getter
|
||||
// Note: This is a simple wrapper - for actual tests, define getter functions directly
|
||||
|
||||
// Helper function to verify template output
|
||||
void verifyTemplateOutput(const char* templateData, PlaceholderRegistry& registry, const String& expected);
|
||||
|
||||
// Helper function to render template to string
|
||||
String renderTemplateToString(const char* templateData, PlaceholderRegistry& registry, size_t bufferSize = 512);
|
||||
|
||||
#endif // TEST_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user