Mark GrpDIB, GrpText, CullingManager and FileLoader PORTED; test the text file loader

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 12:25:28 +09:00
co-authored by Claude Opus 5.5
parent 3c2ef81536
commit 549e12db7c
6 changed files with 449 additions and 33 deletions
+31
View File
@@ -1,5 +1,6 @@
#include "EterBase/StdAfx.h"
#include "EterBase/Utils.h"
#include "EterBase/FileLoader.h"
#include <cstdio>
#include <cstring>
@@ -57,5 +58,35 @@ int main()
PCHAR* argv = CommandLineToArgv(const_cast<PCHAR>("x \"y z\" w"), &argc);
check(argc == 3 && !strcmp(argv[1], "y z"), "CommandLineToArgv");
free(argv);
// FileLoader (40250 EterBase/FileLoader.cpp): Bind keeps a CP949 lead byte and its trail byte together,
// on hosts where char is unsigned too, and takes any pair of '\r'/'\n' as one line break ("\n\n" too).
{
const char text[] = "a \"b c\"\td\r\n\xB0\xA1\tx\n\n\nlast";
CMemoryTextFileLoader loader;
loader.Bind(int(sizeof(text) - 1), text);
check(loader.GetLineCount() == 4 && loader.CheckLineIndex(3) && !loader.CheckLineIndex(4), "TextFileLoader lines");
CTokenVector tokens;
check(loader.SplitLine(0, &tokens) && tokens.size() == 3 && tokens[1] == "b c" && tokens[2] == "d", "SplitLine quoted");
check(loader.SplitLine2(0, &tokens) == 0 && tokens.size() == 3, "SplitLine2");
check(loader.SplitLineByTab(1, &tokens) && tokens.size() == 2 && tokens[0] == "\xB0\xA1" && tokens[1] == "x", "SplitLineByTab CP949");
check(!loader.SplitLine(2, &tokens) && !loader.SplitLineByTab(2, &tokens), "empty line");
check(loader.GetLineString(3) == "last", "last line without newline");
const unsigned char bytes[] = {1, 2, 3, 4, 5};
CMemoryFileLoader mem(5, bytes);
unsigned char got[4] = {};
check(mem.Read(3, got) && got[2] == 3 && mem.GetPosition() == 3 && !mem.Read(3, got) && mem.GetSize() == 5, "MemoryFileLoader");
char path[] = "/tmp/mt_fileloader_XXXXXX";
int fd = mkstemp(path);
FILE * fp = fdopen(fd, "wb");
fwrite(bytes, 1, 5, fp);
fclose(fp);
CDiskFileLoader disk;
check(disk.Open(path) && disk.GetSize() == 5 && disk.Read(4, got) && got[3] == 4, "DiskFileLoader");
disk.Close();
check(!disk.Open("/nonexistent/mt_fileloader"), "DiskFileLoader missing");
remove(path);
}
return failures ? 1 : 0;
}