diff --git a/tests/stb.c b/tests/stb.c
index a8a62b4..508cefa 100644
--- a/tests/stb.c
+++ b/tests/stb.c
@@ -19,9 +19,10 @@
#define STB_MALLOC_WRAPPER_DEBUG
#endif
#define STB_NPTR
+#define STB_DEFINE
#include "stb.h"
-#include "stb_file.h"
-#include "stb_pixel32.h"
+//#include "stb_file.h"
+//#include "stb_pixel32.h"
//#define DEBUG_BLOCK
#ifdef DEBUG_BLOCK
@@ -550,101 +551,6 @@ void bst_test(void)
}
}
-#define BN 800
-unsigned int bloc[BN];
-char *data[BN];
-int dlen[BN];
-
-int bcheck(stb_blockfile *b, int n)
-{
- char temp[2048];
- if (!stb_blockfile_read(b, temp, bloc[n], dlen[n])) {
- c(0, "blockfile_test read error");
- bloc[n] = 0;
- return 0;
- }
- if (memcmp(temp, data[n], dlen[n])) {
- c(0, "blockfile_test read");
- bloc[n] = 0;
- return 0;
- }
- return 1;
-}
-
-void blockfile_test(void)
-{
- int inuse=0, max_inuse=0;
- int i,j,freespace=0;
- int z;
- stb_blockfile *b;
- int o[BN];
-
- b = stb_blockfile_open("btest.bin", 1);
-
- for (i=0; i < BN; ++i) {
- bloc[i] = 0;
- dlen[i] = stb_rand() % 500 + 50;
- data[i] = malloc(1024);
- for (j=0; j < dlen[i]; ++j)
- data[i][j] = (char) stb_rand();
- }
-
- for(z=0; z < 50; ++z) {
- if (z % 4 == 3) {
- //if (!b->dirty_flag) stb__dirty(b);
- stb_blockfile_close(b);
- b = stb_blockfile_open("btest.bin", 0);
- //if (!b->dirty_flag) stb__dirty(b);
- }
- for (i=0; i < BN; ++i) o[i] = i;
- stb_shuffle(o, BN, sizeof(o[0]), stb_rand());
- for (i=0; i < BN; ++i) {
- int n = o[i];
- if (bloc[n] > 0) {
- // first check it
- if (!bcheck(b,n)) continue;
- if (stb_rand() % 100 > 75) {
- stb_blockfile_free(b, bloc[n], dlen[n]);
- bloc[n] = 0;
- inuse -= dlen[n];
- } else if (stb_rand() % 100 > 75) {
- int olen = dlen[n];
- dlen[n] = stb_rand() % 500 + 50;
- for (j=0; j < dlen[n]; ++j)
- data[n][j] = (char) stb_rand();
- bloc[n] = stb_blockfile_rewrite(b, data[n], dlen[n], bloc[n], olen);
- inuse = inuse + dlen[n] - olen;
- }
- } else {
- if (stb_rand() % 100 > 40) {
- bloc[n] = stb_blockfile_write(b, data[n], dlen[n]);
- assert(bloc[n]);
- inuse += dlen[n];
- }
- }
- if (inuse > max_inuse) max_inuse = inuse;
- }
- #ifdef DEBUG_BLOCK
- printf("Pass %d\n", z+1);
- stb_block_compact_freelist(b->manager);
- qsort(b->manager->freelist, b->manager->len, 8, stb__freelist_compare);
- for (i=0; i < b->manager->len; ++i)
- printf("%9d %9d\n", b->manager->freelist[i].start, b->manager->freelist[i].len);
- _getch();
- #endif
- }
-
- freespace = 0;
- for (i=0; i < b->manager->len; ++i)
- freespace += b->manager->freelist[i].len;
-
- printf("Max data: %d; Inuse: %d; freespace: %d (%d)\n", max_inuse, inuse, freespace, b->manager->len);
- stb_blockfile_close(b);
-
- for (i=0; i < BN; ++i)
- free(data[i]);
-}
-
extern void stu_uninit(void);
stb_define_sort(sort_int, int, *a < *b)
@@ -677,7 +583,6 @@ int main(int argc, char **argv)
char **s;
char buf[256], *p;
int n,len2,*q,i;
- stb_mml *m;
stb_matcher *mt=NULL;
if (argc > 1) {
@@ -764,6 +669,7 @@ int main(int argc, char **argv)
c(stb_alloc_count_alloc == stb_alloc_count_free, "stb_alloc 0");
+#if 0
// stb_block
{
int inuse=0, freespace=0;
@@ -835,7 +741,8 @@ int main(int argc, char **argv)
free(x);
}
-// blockfile_test();
+ blockfile_test();
+#endif
mt = stb_lex_matcher();
for (i=0; i < 5; ++i)
@@ -1111,6 +1018,7 @@ int main(int argc, char **argv)
c(s == NULL && n == 0 , "stb_getopt 5");
stb_getopt_free(s);
+#if 0
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, -1, -1) == 1, "stb_csample_int 1");
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, 1, -3) == 2, "stb_csample_int 2");
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, 12, -2) == 5, "stb_csample_int 3");
@@ -1120,6 +1028,7 @@ int main(int argc, char **argv)
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, -2, 5) == 11, "stb_csample_int 7");
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, -7, 0) == 1, "stb_csample_int 8");
c(*stb_csample_int(sample_test[0], 1, 5, 5, 3, 2, 1) == 8, "stb_csample_int 9");
+#endif
c(!strcmp(stb_splitpath(buf, p1, STB_PATH ), "foo/bar\\baz/"), "stb_splitpath 1");
c(!strcmp(stb_splitpath(buf, p1, STB_FILE ), "test"), "stb_splitpath 2");
@@ -1149,6 +1058,7 @@ int main(int argc, char **argv)
c(!strcmp(p=stb_dupreplace("abacab", "a", "aba"), "abababacabab" ), "stb_dupreplace 3"); free(p);
+#if 0
m = stb_mml_parse("xy<&f>");
c(m != NULL, "stb_mml_parse 1");
if (m) {
@@ -1161,6 +1071,7 @@ int main(int argc, char **argv)
if (stb_alloc_count_alloc != stb_alloc_count_free) {
printf("%d allocs, %d frees\n", stb_alloc_count_alloc, stb_alloc_count_free);
}
+#endif
c(stb_linear_remap(3.0f,0,8,1,2) == 1.375, "stb_linear_remap()");
diff --git a/tests/stb.dsp b/tests/stb.dsp
new file mode 100644
index 0000000..8e544be
--- /dev/null
+++ b/tests/stb.dsp
@@ -0,0 +1,92 @@
+# Microsoft Developer Studio Project File - Name="stb" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=stb - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "stb.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "stb.mak" CFG="stb - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "stb - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "stb - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "stb - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /G6 /MT /W3 /GX /Z7 /O2 /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
+
+!ELSEIF "$(CFG)" == "stb - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /pdbtype:sept
+# SUBTRACT LINK32 /force
+
+!ENDIF
+
+# Begin Target
+
+# Name "stb - Win32 Release"
+# Name "stb - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\stb.c
+# End Source File
+# End Target
+# End Project
diff --git a/tests/stb.dsw b/tests/stb.dsw
new file mode 100644
index 0000000..374e2b4
--- /dev/null
+++ b/tests/stb.dsw
@@ -0,0 +1,44 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "stb"=.\stb.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name stb_cpp
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "stb_cpp"=.\stb_cpp.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/tests/stb_cpp.cpp b/tests/stb_cpp.cpp
new file mode 100644
index 0000000..94a7310
--- /dev/null
+++ b/tests/stb_cpp.cpp
@@ -0,0 +1,83 @@
+#define WIN32_MEAN_AND_LEAN
+#define WIN32_LEAN_AND_MEAN
+//#include
+#include
+#define STB_STUA
+#define STB_DEFINE
+#define STB_NPTR
+#define STB_ONLY
+#include "stb.h"
+//#include "stb_file.h"
+
+int count;
+void c(int truth, char *error)
+{
+ if (!truth) {
+ fprintf(stderr, "Test failed: %s\n", error);
+ ++count;
+ }
+}
+
+char *expects(stb_matcher *m, char *s, int result, int len, char *str)
+{
+ int res2,len2=0;
+ res2 = stb_lex(m, s, &len2);
+ c(result == res2 && len == len2, str);
+ return s + len;
+}
+
+void test_lex(void)
+{
+ stb_matcher *m = stb_lex_matcher();
+ // tok_en5 .3 20.1 20. .20 .1
+ char *s = "tok_en5.3 20.1 20. .20.1";
+
+ stb_lex_item(m, "[a-zA-Z_][a-zA-Z0-9_]*", 1 );
+ stb_lex_item(m, "[0-9]*\\.?[0-9]*" , 2 );
+ stb_lex_item(m, "[\r\n\t ]+" , 3 );
+ stb_lex_item(m, "." , -99 );
+ s=expects(m,s,1,7, "stb_lex 1");
+ s=expects(m,s,2,2, "stb_lex 2");
+ s=expects(m,s,3,1, "stb_lex 3");
+ s=expects(m,s,2,4, "stb_lex 4");
+ s=expects(m,s,3,1, "stb_lex 5");
+ s=expects(m,s,2,3, "stb_lex 6");
+ s=expects(m,s,3,1, "stb_lex 7");
+ s=expects(m,s,2,3, "stb_lex 8");
+ s=expects(m,s,2,2, "stb_lex 9");
+ s=expects(m,s,0,0, "stb_lex 10");
+ stb_matcher_free(m);
+}
+
+int main(int argc, char **argv)
+{
+ char *p;
+ p = "abcdefghijklmnopqrstuvwxyz";
+ c(stb_ischar('c', p), "stb_ischar 1");
+ c(stb_ischar('x', p), "stb_ischar 2");
+ c(!stb_ischar('#', p), "stb_ischar 3");
+ c(!stb_ischar('X', p), "stb_ischar 4");
+ p = "0123456789";
+ c(!stb_ischar('c', p), "stb_ischar 5");
+ c(!stb_ischar('x', p), "stb_ischar 6");
+ c(!stb_ischar('#', p), "stb_ischar 7");
+ c(!stb_ischar('X', p), "stb_ischar 8");
+ p = "#####";
+ c(!stb_ischar('c', p), "stb_ischar a");
+ c(!stb_ischar('x', p), "stb_ischar b");
+ c(stb_ischar('#', p), "stb_ischar c");
+ c(!stb_ischar('X', p), "stb_ischar d");
+ p = "xXyY";
+ c(!stb_ischar('c', p), "stb_ischar e");
+ c(stb_ischar('x', p), "stb_ischar f");
+ c(!stb_ischar('#', p), "stb_ischar g");
+ c(stb_ischar('X', p), "stb_ischar h");
+
+ test_lex();
+
+ if (count) {
+ _getch();
+ }
+ return 0;
+}
+
\ No newline at end of file
diff --git a/tests/stb_cpp.dsp b/tests/stb_cpp.dsp
new file mode 100644
index 0000000..98b9574
--- /dev/null
+++ b/tests/stb_cpp.dsp
@@ -0,0 +1,88 @@
+# Microsoft Developer Studio Project File - Name="stb_cpp" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=stb_cpp - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "stb_cpp.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "stb_cpp.mak" CFG="stb_cpp - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "stb_cpp - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "stb_cpp - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "stb_cpp - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "stb_cpp - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "stb_cpp - Win32 Release"
+# Name "stb_cpp - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\stb_cpp.cpp
+# End Source File
+# End Target
+# End Project