Add a /c option to supply a comment for the web service submission.
[reactos.git] / rostests / rosautotest / main.c
index 85acfd8..4bfc8bd 100644 (file)
@@ -66,62 +66,76 @@ IntGetConfigurationValues()
     const CHAR PasswordProp[] = "&password=";
     const CHAR UserNameProp[] = "&username=";
 
+    BOOL ReturnValue = FALSE;
     DWORD DataLength;
     DWORD Length;
-    PCHAR Password;
-    PCHAR UserName;
+    PCHAR Password = NULL;
+    PCHAR UserName = NULL;
     WCHAR ConfigFile[MAX_PATH];
 
-    /* We only need this if the results are going to be submitted */
-    if(!AppOptions.Submit)
-        return TRUE;
+    /* Most values are only needed if we're going to submit */
+    if(AppOptions.Submit)
+    {
+        /* Build the path to the configuration file from the application's path */
+        GetModuleFileNameW(NULL, ConfigFile, MAX_PATH);
+        Length = wcsrchr(ConfigFile, '\\') - ConfigFile;
+        wcscpy(&ConfigFile[Length], L"\\rosautotest.ini");
 
-    /* Build the path to the configuration file from the application's path */
-    GetModuleFileNameW(NULL, ConfigFile, MAX_PATH);
-    Length = wcsrchr(ConfigFile, '\\') - ConfigFile;
-    wcscpy(&ConfigFile[Length], L"\\rosautotest.ini");
+        /* Check if it exists */
+        if(GetFileAttributesW(ConfigFile) == INVALID_FILE_ATTRIBUTES)
+        {
+            StringOut("Missing \"rosautotest.ini\" configuration file!\n");
+            goto Cleanup;
+        }
 
-    /* Check if it exists */
-    if(GetFileAttributesW(ConfigFile) == INVALID_FILE_ATTRIBUTES)
-    {
-        StringOut("Missing \"rosautotest.ini\" configuration file!\n");
-        return FALSE;
-    }
+        /* Get the required length of the authentication request string */
+        DataLength = sizeof(UserNameProp) - 1;
+        Length = IntGetINIValueA(L"Login", L"UserName", ConfigFile, &UserName);
 
-    /* Get the required length of the authentication request string */
-    DataLength = sizeof(UserNameProp) - 1;
-    Length = IntGetINIValueA(L"Login", L"UserName", ConfigFile, &UserName);
+        if(!Length)
+        {
+            StringOut("UserName is missing in the configuration file\n");
+            goto Cleanup;
+        }
 
-    if(!Length)
-    {
-        StringOut("UserName is missing in the configuration file\n");
-        return FALSE;
-    }
+        /* Some characters might need to be escaped and an escaped character takes 3 bytes */
+        DataLength += 3 * Length;
 
-    /* Some characters might need to be escaped and an escaped character takes 3 bytes */
-    DataLength += 3 * Length;
+        DataLength += sizeof(PasswordProp) - 1;
+        Length = IntGetINIValueA(L"Login", L"Password", ConfigFile, &Password);
 
-    DataLength += sizeof(PasswordProp) - 1;
-    Length = IntGetINIValueA(L"Login", L"Password", ConfigFile, &Password);
+        if(!Length)
+        {
+            StringOut("Password is missing in the configuration file\n");
+            goto Cleanup;
+        }
 
-    if(!Length)
-    {
-        StringOut("Password is missing in the configuration file\n");
-        return FALSE;
-    }
+        DataLength += 3 * Length;
 
-    DataLength += 3 * Length;
+        /* Build the string */
+        AuthenticationRequestString = HeapAlloc(hProcessHeap, 0, DataLength + 1);
 
-    /* Build the string */
-    AuthenticationRequestString = HeapAlloc(hProcessHeap, 0, DataLength + 1);
+        strcpy(AuthenticationRequestString, UserNameProp);
+        EscapeString(&AuthenticationRequestString[strlen(AuthenticationRequestString)], UserName);
 
-    strcpy(AuthenticationRequestString, UserNameProp);
-    EscapeString(&AuthenticationRequestString[strlen(AuthenticationRequestString)], UserName);
+        strcat(AuthenticationRequestString, PasswordProp);
+        EscapeString(&AuthenticationRequestString[strlen(AuthenticationRequestString)], Password);
 
-    strcat(AuthenticationRequestString, PasswordProp);
-    EscapeString(&AuthenticationRequestString[strlen(AuthenticationRequestString)], Password);
+        /* If we don't have any Comment string yet, try to find one in the INI file */
+        if(!AppOptions.Comment)
+            IntGetINIValueA(L"Submission", L"Comment", ConfigFile, &AppOptions.Comment);
+    }
 
-    return TRUE;
+    ReturnValue = TRUE;
+
+Cleanup:
+    if(UserName)
+        HeapFree(hProcessHeap, 0, UserName);
+
+    if(Password)
+        HeapFree(hProcessHeap, 0, Password);
+
+    return ReturnValue;
 }
 
 /**
@@ -222,10 +236,13 @@ IntPrintUsage()
     printf("rosautotest - ReactOS Automatic Testing Utility\n");
     printf("Usage: rosautotest [options] [module] [test]\n");
     printf("  options:\n");
-    printf("    /?  - Shows this help\n");
-    printf("    /s  - Shut down the system after finishing the tests\n");
-    printf("    /w  - Submit the results to the webservice\n");
-    printf("          Requires a \"rosautotest.ini\" with valid login data.\n");
+    printf("    /?           - Shows this help\n");
+    printf("    /c <comment> - Specifies the comment to be submitted to the Web Service.\n");
+    printf("                   Skips the comment set in the configuration file (if any).\n");
+    printf("                   Only has an effect when /w is also used.\n");
+    printf("    /s           - Shut down the system after finishing the tests\n");
+    printf("    /w           - Submit the results to the webservice\n");
+    printf("                   Requires a \"rosautotest.ini\" with valid login data.\n");
     printf("\n");
     printf("  module:\n");
     printf("    The module to be tested (i.e. \"advapi32\")\n");
@@ -242,7 +259,8 @@ IntPrintUsage()
 int
 wmain(int argc, wchar_t* argv[])
 {
-    int Result = 0;
+    int ReturnValue = 0;
+    size_t Length;
     UINT i;
 
     hProcessHeap = GetProcessHeap();
@@ -254,6 +272,16 @@ wmain(int argc, wchar_t* argv[])
         {
             switch(argv[i][1])
             {
+                case 'c':
+                    ++i;
+
+                    /* Copy the parameter converted to ASCII */
+                    Length = WideCharToMultiByte(CP_ACP, 0, argv[i], -1, NULL, 0, NULL, NULL);
+                    AppOptions.Comment = HeapAlloc(hProcessHeap, 0, Length);
+                    WideCharToMultiByte(CP_ACP, 0, argv[i], -1, AppOptions.Comment, Length, NULL, NULL);
+
+                    break;
+
                 case 's':
                     AppOptions.Shutdown = TRUE;
                     break;
@@ -263,18 +291,16 @@ wmain(int argc, wchar_t* argv[])
                     break;
 
                 default:
-                    Result = 1;
+                    ReturnValue = 1;
                     /* Fall through */
 
                 case '?':
                     IntPrintUsage();
-                    goto End;
+                    goto Cleanup;
             }
         }
         else
         {
-            size_t Length;
-
             /* Which parameter is this? */
             if(!AppOptions.Module)
             {
@@ -292,24 +318,26 @@ wmain(int argc, wchar_t* argv[])
             }
             else
             {
-                Result = 1;
+                ReturnValue = 1;
                 IntPrintUsage();
-                goto End;
+                goto Cleanup;
             }
         }
     }
 
     if(!IntGetConfigurationValues() || !IntGetBuildAndPlatform() || !RunWineTests())
     {
-        Result = 1;
-        goto End;
+        ReturnValue = 1;
+        goto Cleanup;
     }
 
     /* For sysreg */
     OutputDebugStringA("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
 
-End:
-    /* Cleanup */
+Cleanup:
+    if(AppOptions.Comment)
+        HeapFree(hProcessHeap, 0, AppOptions.Comment);
+
     if(AppOptions.Module)
         HeapFree(hProcessHeap, 0, AppOptions.Module);
 
@@ -324,7 +352,7 @@ End:
 
     /* Shut down the system if requested */
     if(AppOptions.Shutdown && !ShutdownSystem())
-        Result = 1;
+        ReturnValue = 1;
 
-    return Result;
+    return ReturnValue;
 }