sync rostests to r44455
[reactos.git] / rostests / winetests / setupapi / parser.c
index 6341222..06bffaf 100644 (file)
 /* function pointers */
 static HMODULE hSetupAPI;
 static LPCWSTR (WINAPI *pSetupGetField)(PINFCONTEXT,DWORD);
+static BOOL (WINAPI *pSetupEnumInfSectionsA)( HINF hinf, UINT index, PSTR buffer, DWORD size, UINT *need );
 
 static void init_function_pointers(void)
 {
     hSetupAPI = GetModuleHandleA("setupapi.dll");
 
     pSetupGetField = (void *)GetProcAddress(hSetupAPI, "pSetupGetField"); 
+    pSetupEnumInfSectionsA = (void *)GetProcAddress(hSetupAPI, "SetupEnumInfSectionsA" );
 }
 
 static const char tmpfilename[] = ".\\tmp.inf";
@@ -52,6 +54,7 @@ static const char tmpfilename[] = ".\\tmp.inf";
 #define A400 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
              "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
              "aaaaaaaaaaaaaaaa" A256
+#define A1200 A400 A400 A400
 #define A511 A255 A256
 #define A4097 "a" A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256 A256
 
@@ -61,7 +64,7 @@ static const char tmpfilename[] = ".\\tmp.inf";
                     "per%%cent=abcd\nper=1\ncent=2\n22=foo\n" \
                     "big=" A400 "\n" \
                     "mydrive=\"C:\\\"\n" \
-                    "verybig=" A400 A400 A400 "\n"
+                    "verybig=" A1200 "\n"
 
 /* create a new file with specified contents and open it */
 static HINF test_file_contents( const char *data, UINT *err_line )
@@ -245,6 +248,52 @@ static void test_section_names(void)
     }
 }
 
+static void test_enum_sections(void)
+{
+    static const char *contents = STD_HEADER "[s1]\nfoo=bar\n[s2]\nbar=foo\n[s3]\n[strings]\na=b\n";
+
+    BOOL ret;
+    DWORD len;
+    HINF hinf;
+    UINT err, index;
+    char buffer[256];
+
+    if (!pSetupEnumInfSectionsA)
+    {
+        win_skip( "SetupEnumInfSectionsA not available\n" );
+        return;
+    }
+
+    hinf = test_file_contents( contents, &err );
+    ok( hinf != NULL, "Expected valid INF file\n" );
+
+    for (index = 0; ; index++)
+    {
+        SetLastError( 0xdeadbeef );
+        ret = pSetupEnumInfSectionsA( hinf, index, NULL, 0, &len );
+        err = GetLastError();
+        if (!ret && GetLastError() == ERROR_NO_MORE_ITEMS) break;
+        ok( ret, "SetupEnumInfSectionsA failed\n" );
+        ok( len == 3 || len == 8, "wrong len %u\n", len );
+
+        SetLastError( 0xdeadbeef );
+        ret = pSetupEnumInfSectionsA( hinf, index, NULL, sizeof(buffer), &len );
+        err = GetLastError();
+        ok( !ret, "SetupEnumInfSectionsA succeeded\n" );
+        ok( err == ERROR_INVALID_USER_BUFFER, "wrong error %u\n", err );
+        ok( len == 3 || len == 8, "wrong len %u\n", len );
+
+        SetLastError( 0xdeadbeef );
+        ret = pSetupEnumInfSectionsA( hinf, index, buffer, sizeof(buffer), &len );
+        ok( ret, "SetupEnumInfSectionsA failed err %u\n", GetLastError() );
+        ok( len == 3 || len == 8, "wrong len %u\n", len );
+        ok( !lstrcmpi( buffer, "version" ) || !lstrcmpi( buffer, "s1" ) ||
+            !lstrcmpi( buffer, "s2" ) || !lstrcmpi( buffer, "s3" ) || !lstrcmpi( buffer, "strings" ),
+            "bad section '%s'\n", buffer );
+    }
+    SetupCloseInfFile( hinf );
+}
+
 
 /* Test various key and value names */
 
@@ -315,7 +364,7 @@ static const struct
  { "loop=%loop%\n" STR_SECTION,     "loop",  { "%loop2%" } },
  { "%per%%cent%=100\n" STR_SECTION, "12",    { "100" } },
  { "a=%big%\n" STR_SECTION,         "a",     { A400 } },
- { "a=%verybig%\n" STR_SECTION,     "a",     { A511 } },  /* truncated to 511 */
+ { "a=%verybig%\n" STR_SECTION,     "a",     { A511 } },  /* truncated to 511, not on Vista/W2K8 */
  { "a=%big%%big%%big%%big%\n" STR_SECTION,   "a", { A400 A400 A400 A400 } },
  { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION,   "a", { A400 A400 A400 A400 A400 A400 A400 A400 A400 } },
  { "a=%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%%big%\n" STR_SECTION,   "a", { A4097 /*MAX_INF_STRING_LENGTH+1*/ } },
@@ -384,8 +433,21 @@ static void test_key_names(void)
             {
                 ok( err == 0, "line %u: bad error %u\n", i, err );
                 if (key_names[i].fields[index])
+                {
+                    if (i == 49)
+                        ok( !strcmp( field, key_names[i].fields[index] ) ||
+                            !strcmp( field, A1200), /* Vista, W2K8 */
+                            "line %u: bad field %s/%s\n",
+                            i, field, key_names[i].fields[index] );
+                    else  /* don't compare drive letter of paths */
+                        if (field[0] && field[1] == ':' && field[2] == '\\')
+                        ok( !strcmp( field + 1, key_names[i].fields[index] + 1 ),
+                            "line %u: bad field %s/%s\n",
+                            i, field, key_names[i].fields[index] );
+                    else
                     ok( !strcmp( field, key_names[i].fields[index] ), "line %u: bad field %s/%s\n",
                         i, field, key_names[i].fields[index] );
+                }
                 else
                     ok( 0, "line %u: got extra field %s\n", i, field );
                 strcat( buffer, "," );
@@ -416,12 +478,15 @@ static void test_close_inf_file(void)
 {
     SetLastError(0xdeadbeef);
     SetupCloseInfFile(NULL);
-    ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", GetLastError());
+    ok(GetLastError() == 0xdeadbeef ||
+        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x, WinMe */
+        "Expected 0xdeadbeef, got %u\n", GetLastError());
 
     SetLastError(0xdeadbeef);
     SetupCloseInfFile(INVALID_HANDLE_VALUE);
-    ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", GetLastError());
-
+    ok(GetLastError() == 0xdeadbeef ||
+        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x, WinMe */
+        "Expected 0xdeadbeef, got %u\n", GetLastError());
 }
 
 static const char *contents = "[Version]\n"
@@ -447,6 +512,7 @@ static void test_pSetupGetField(void)
     LPCWSTR field;
     INFCONTEXT context;
     int i;
+    int len;
 
     hinf = test_file_contents( contents, &err );
     ok( hinf != NULL, "Expected valid INF file\n" );
@@ -465,7 +531,11 @@ static void test_pSetupGetField(void)
 
     field = pSetupGetField( &context, 3 );
     ok( field != NULL, "Failed to get field 3\n" );
-    ok( lstrlenW( field ) == 511, "Expected 511, got %d\n", lstrlenW( field ) );
+    len = lstrlenW( field );
+    ok( len == 511 /* NT4, W2K, XP and W2K3 */ ||
+        len == 4096 /* Vista */ ||
+        len == 256 /* Win9x and WinME */,
+        "Unexpected length, got %d\n", len );
 
     field = pSetupGetField( &context, 4 );
     ok( field == NULL, "Expected NULL, got %p\n", field );
@@ -519,18 +589,18 @@ static void test_SetupGetIntField(void)
         retb = SetupGetIntField( &context, keys[i].index, &intfield );
         if ( keys[i].err == ERROR_SUCCESS )
         {
-            ok( retb, "Expected success\n" );
+            ok( retb, "%u: Expected success\n", i );
             ok( GetLastError() == ERROR_SUCCESS ||
                 GetLastError() == 0xdeadbeef /* win9x, NT4 */,
-                "Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", GetLastError() );
+                "%u: Expected ERROR_SUCCESS or 0xdeadbeef, got %u\n", i, GetLastError() );
         }
         else
         {
-            ok( !retb, "Expected failure\n" );
+            ok( !retb, "%u: Expected failure\n", i );
             ok( GetLastError() == keys[i].err,
-                "Expected %d, got %u\n", keys[i].err, GetLastError() );
+                "%u: Expected %d, got %u\n", i, keys[i].err, GetLastError() );
         }
-        ok( intfield == keys[i].value, "Expected %d, got %d\n", keys[i].value, intfield );
+        ok( intfield == keys[i].value, "%u: Expected %d, got %d\n", i, keys[i].value, intfield );
 
         SetupCloseInfFile( hinf );
     }
@@ -655,6 +725,7 @@ START_TEST(parser)
     init_function_pointers();
     test_invalid_files();
     test_section_names();
+    test_enum_sections();
     test_key_names();
     test_close_inf_file();
     test_pSetupGetField();