Author: mjansen
Date: Thu Jun 2 18:59:04 2016
New Revision: 71501
URL:
http://svn.reactos.org/svn/reactos?rev=71501&view=rev
Log:
[APPHELP_APITEST][APPHELP] Add new tests showing that SdbWriteStringTag and
SdbEndWriteListTag are incorrect, fix SdbEndWriteListTag CORE-10367
SdbWriteStringTag requires the database to keep track of written strings, and append a
stringtable to a database.
Modified:
trunk/reactos/dll/appcompat/apphelp/sdbapi.c
trunk/reactos/dll/appcompat/apphelp/sdbpapi.h
trunk/reactos/dll/appcompat/apphelp/sdbwrite.c
trunk/rostests/apitests/apphelp/db.c
Modified: trunk/reactos/dll/appcompat/apphelp/sdbapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdba…
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbapi.c [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbapi.c [iso-8859-1] Thu Jun 2 18:59:04 2016
@@ -259,12 +259,17 @@
DWORD SdbpStrlen(PCWSTR string)
{
- return (lstrlenW(string) + 1) * sizeof(WCHAR);
+ return lstrlenW(string);
+}
+
+DWORD SdbpStrsize(PCWSTR string)
+{
+ return (SdbpStrlen(string) + 1) * sizeof(WCHAR);
}
PWSTR SdbpStrDup(LPCWSTR string)
{
- PWSTR ret = SdbpAlloc(SdbpStrlen(string));
+ PWSTR ret = SdbpAlloc(SdbpStrsize(string));
lstrcpyW(ret, string);
return ret;
}
Modified: trunk/reactos/dll/appcompat/apphelp/sdbpapi.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbp…
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbpapi.h [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbpapi.h [iso-8859-1] Thu Jun 2 18:59:04 2016
@@ -65,7 +65,8 @@
PDB WINAPI SdbpCreate(LPCWSTR path, PATH_TYPE type, BOOL write);
void WINAPI SdbpFlush(PDB db);
-DWORD SdbpStrlen(LPCWSTR string);
+DWORD SdbpStrlen(PCWSTR string);
+DWORD SdbpStrsize(PCWSTR string);
#ifdef __cplusplus
Modified: trunk/reactos/dll/appcompat/apphelp/sdbwrite.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbw…
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbwrite.c [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbwrite.c [iso-8859-1] Thu Jun 2 18:59:04 2016
@@ -36,6 +36,10 @@
#include "sdbtagid.h"
#endif
+
+BOOL WINAPI SdbWriteStringRefTag(PDB db, TAG tag, TAGID tagid);
+TAGID WINAPI SdbBeginWriteListTag(PDB db, TAG tag);
+BOOL WINAPI SdbEndWriteListTag(PDB db, TAGID tagid);
static void WINAPI SdbpWrite(PDB db, const void* data, DWORD size)
@@ -51,6 +55,23 @@
db->write_iter += size;
}
+static BOOL WINAPI SdbpGetOrAddStringRef(PDB db, LPCWSTR string, TAGID* tagid)
+{
+ /* TODO:
+ - Insert or find in stringtable
+ - return TAGID
+ */
+
+ return FALSE;
+}
+
+static void WINAPI SdbpWriteStringtable(PDB db)
+{
+ TAGID table = SdbBeginWriteListTag(db, TAG_STRINGTABLE);
+ /* TODO: Write out all strings*/
+ SdbEndWriteListTag(db, table);
+}
+
/**
* Creates new shim database file
*
@@ -90,6 +111,7 @@
*/
void WINAPI SdbCloseDatabaseWrite(PDB db)
{
+ SdbpWriteStringtable(db);
SdbpFlush(db);
SdbCloseDatabase(db);
}
@@ -181,10 +203,19 @@
{
DWORD size;
+ if (SdbpCheckTagType(tag, TAG_TYPE_STRINGREF))
+ {
+ TAGID tagid = 0;
+ if (!SdbpGetOrAddStringRef(db, string, &tagid))
+ return FALSE;
+
+ return SdbWriteStringRefTag(db, tag, tagid);
+ }
+
if (!SdbpCheckTagType(tag, TAG_TYPE_STRING))
return FALSE;
- size = SdbpStrlen(string);
+ size = SdbpStrsize(string);
SdbpWrite(db, &tag, sizeof(TAG));
SdbpWrite(db, &size, sizeof(size));
SdbpWrite(db, string, size);
@@ -297,7 +328,7 @@
return FALSE;
/* Write size of list to list tag header */
- *(DWORD*)&db->data[tagid + sizeof(TAG)] = db->write_iter - tagid -
sizeof(TAG);
- return TRUE;
-}
-
+ *(DWORD*)&db->data[tagid + sizeof(TAG)] = db->write_iter - tagid -
sizeof(TAG) - sizeof(TAGID);
+ return TRUE;
+}
+
Modified: trunk/rostests/apitests/apphelp/db.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/apphelp/db.c?rev…
==============================================================================
--- trunk/rostests/apitests/apphelp/db.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/apphelp/db.c [iso-8859-1] Thu Jun 2 18:59:04 2016
@@ -312,6 +312,91 @@
}
DeleteFileW(path1);
}
+
+/*
+ - Show that a stringtable is automatically generated,
+ - validate multiple lists (for the length)
+*/
+static void test_write_ex(void)
+{
+ WCHAR path1[] =
{'t','e','s','t','.','s','d','b',0};
+ WCHAR test1[] = {'T','E','S','T',0};
+ WCHAR test2[] = {'t','e','s','t',0};
+ PDB pdb;
+ TAGID tagdb, tagstr;
+ TAG tag;
+ DWORD size;
+ BOOL ret;
+
+ /* Write a small database */
+ pdb = pSdbCreateDatabase(path1, DOS_PATH);
+ ok(pdb != NULL, "Expected a valid database\n");
+ if (!pdb)
+ return;
+ tagdb = pSdbBeginWriteListTag(pdb, TAG_DATABASE);
+ ok(tagdb == 12, "Expected tag to be 12, was %u\n", tagdb);
+ ret = pSdbWriteStringTag(pdb, TAG_NAME, test1);
+ ok(ret, "Expected SdbWriteStringTag to succeed\n");
+ ret = pSdbEndWriteListTag(pdb, tagdb);
+ ok(ret, "Expected SdbEndWriteListTag to succeed\n");
+
+ tagdb = pSdbBeginWriteListTag(pdb, TAG_DATABASE);
+ ok(tagdb == 24, "Expected tag to be 24, was %u\n", tagdb);
+ ret = pSdbWriteStringTag(pdb, TAG_NAME, test2);
+ ok(ret, "Expected SdbWriteStringTag to succeed\n");
+ ret = pSdbEndWriteListTag(pdb, tagdb);
+ ok(ret, "Expected SdbEndWriteListTag to succeed\n");
+
+ pSdbCloseDatabaseWrite(pdb);
+
+ /* Now validate it's contents */
+ pdb = pSdbOpenDatabase(path1, DOS_PATH);
+ ok(pdb != NULL, "Expected a valid database\n");
+ if (!pdb)
+ return;
+ tagdb = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
+ ok(tagdb == 12, "Expected tag to be 12, was %u\n", tagdb);
+ size = pSdbGetTagDataSize(pdb, tagdb);
+ ok(size == 6, "Expected size to be 6, was %u\n", size);
+ tagstr = pSdbFindFirstTag(pdb, tagdb, TAG_NAME);
+ ok(tagstr == 18, "Expected string tag to be 18, was %u\n", tagstr);
+ tag = pSdbGetTagFromTagID(pdb, tagstr);
+ ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n",
(DWORD)tag);
+ size = pSdbGetTagDataSize(pdb, tagstr);
+ ok(size == 4, "Expected size to be 4, was 0x%x\n", size);
+
+ tagdb = pSdbFindNextTag(pdb, TAGID_ROOT, tagdb);
+ ok(tagdb == 24, "Expected tag to be 24, was %u\n", tagdb);
+ size = pSdbGetTagDataSize(pdb, tagdb);
+ ok(size == 6, "Expected size to be 6, was %u\n", size);
+ tagstr = pSdbFindFirstTag(pdb, tagdb, TAG_NAME);
+ ok(tagstr == 30, "Expected string tag to be 30, was %u\n", tagstr);
+ tag = pSdbGetTagFromTagID(pdb, tagstr);
+ ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n",
(DWORD)tag);
+ size = pSdbGetTagDataSize(pdb, tagstr);
+ ok(size == 4, "Expected size to be 4, was %u\n", size);
+
+ tagdb = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_STRINGTABLE);
+ ok(tagdb == 36, "Expected tag to be 36, was %u\n", tagdb);
+ size = pSdbGetTagDataSize(pdb, tagdb);
+ ok(size == 32, "Expected size to be 32, was %u\n", size);
+ tagstr = pSdbGetFirstChild(pdb, tagdb);
+ ok(tagstr == 42, "Expected string tag to be 42, was %u\n", tagstr);
+ tag = pSdbGetTagFromTagID(pdb, tagstr);
+ ok(tag == TAG_STRINGTABLE_ITEM, "Expected tag to be TAG_STRINGTABLE_ITEM, was
0x%x\n", (DWORD)tag);
+ size = pSdbGetTagDataSize(pdb, tagstr);
+ ok(size == 10, "Expected size to be 10, was %u\n", size);
+
+ tagstr = pSdbGetNextChild(pdb, tagdb, tagstr);
+ ok(tagstr == 58, "Expected string tag to be 58, was %u\n", tagstr);
+ tag = pSdbGetTagFromTagID(pdb, tagstr);
+ ok(tag == TAG_STRINGTABLE_ITEM, "Expected tag to be TAG_STRINGTABLE_ITEM, was
0x%x\n", (DWORD)tag);
+ size = pSdbGetTagDataSize(pdb, tagstr);
+ ok(size == 10, "Expected size to be 10, was %u\n", size);
+
+ pSdbCloseDatabase(pdb);
+}
+
static void match_str_attr_imp(PDB pdb, TAGID parent, TAG find, const char* compare)
{
@@ -790,5 +875,6 @@
pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
test_Sdb();
+ test_write_ex();
test_CheckDatabaseManually();
}