]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/ShellLibTestApp/sa3.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Application / ShellLibTestApp / sa3.c
index 135590bed1847d0ce148ba28f8ac13c51a4afbe3..6418a6cb0a16f22231e3058dbd0b034a18335e32 100644 (file)
@@ -3,18 +3,25 @@
 \r
   This should be executed with "/Param2 Val1" and "/Param1" as the 2 command line options!\r
 \r
-  Copyright (c) 2008, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
+  Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
 #include <Uefi.h>\r
+#include <Guid/FileInfo.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Protocol/EfiShellInterface.h>\r
+#include <Protocol/EfiShellEnvironment2.h>\r
+#include <Protocol/EfiShell.h>\r
+#include <Protocol/EfiShellParameters.h>\r
 #include <Library/UefiApplicationEntryPoint.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/ShellLib.h>\r
 SHELL_PARAM_ITEM ParamList[] = {\r
   {L"/Param1", TypeFlag},\r
   {L"/Param2", TypeValue},\r
+  {L"/Param3", TypeDoubleValue},\r
+  {L"/Param4", TypeMaxValue},\r
   {NULL, TypeMax}};\r
 \r
 /**\r
   as the real entry point for the application.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
   @retval other             Some error occurs when executing this entry point.\r
 \r
@@ -43,7 +52,7 @@ UefiMain (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_FILE_HANDLE     FileHandle;\r
+  SHELL_FILE_HANDLE   FileHandle;\r
   EFI_STATUS          Status;\r
   CHAR16              FileName[100];\r
   UINTN               BufferSize;\r
@@ -54,25 +63,46 @@ UefiMain (
   BOOLEAN             NoFile;\r
   EFI_SHELL_FILE_INFO *pShellFileInfo;\r
   LIST_ENTRY          *List;\r
-  \r
+  // CONST CHAR16              *Tester;\r
+\r
   FileHandle = NULL;\r
   StrCpy(FileName, L"testfile.txt");\r
-  Position = 0;\r
+//  Position = 0;\r
   pFileInfo = NULL;\r
   Size = 0;\r
   NoFile = FALSE;\r
   pShellFileInfo = NULL;\r
   List = NULL;\r
 \r
+  // command line param functions\r
+  Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);\r
+  // if you put an invalid parameter you SHOULD hit this assert.\r
+  ASSERT_EFI_ERROR(Status);\r
+  if (List) {\r
+    ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);\r
+    ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);\r
+    ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);\r
+    ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);\r
+    // Tester = ShellCommandLineGetValue(List, L"/Param3");\r
+    // Tester = ShellCommandLineGetValue(List, L"/Param4");\r
+\r
+    ShellCommandLineFreeVarList(List);\r
+  } else {\r
+    Print(L"param checking skipped.\r\n");\r
+  }\r
+\r
+//  return (EFI_SUCCESS);\r
+\r
+\r
   ASSERT(ShellGetExecutionBreakFlag() == FALSE);\r
-  ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f8:\\") == 0);\r
+  ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0);\r
   Print(L"execution break and get cur dir - pass\r\n");\r
 \r
   ShellSetPageBreakMode(TRUE);\r
 \r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
@@ -100,9 +130,9 @@ UefiMain (
   ASSERT_EFI_ERROR(Status);\r
   Print(L"read, write, create, getinfo - pass\r\n");\r
 \r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
@@ -111,7 +141,7 @@ UefiMain (
   pFileInfo->FileSize = 0x20;\r
   Status = ShellSetFileInfo(FileHandle, pFileInfo);\r
   FreePool(pFileInfo);\r
-  pFileInfo = NULL; \r
+  pFileInfo = NULL;\r
   ASSERT_EFI_ERROR(Status);\r
   pFileInfo = ShellGetFileInfo(FileHandle);\r
   ASSERT(pFileInfo != NULL);\r
@@ -126,10 +156,10 @@ UefiMain (
   Status = ShellCloseFile(&FileHandle);\r
   ASSERT_EFI_ERROR(Status);\r
   Print(L"setinfo and change size, getsize - pass\r\n");\r
-  \r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+\r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
@@ -141,14 +171,14 @@ UefiMain (
   ASSERT(pFileInfo->FileSize == 0x20);\r
   ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r
   FreePool(pFileInfo);\r
-  pFileInfo = NULL;   \r
+  pFileInfo = NULL;\r
   Status = ShellDeleteFile(&FileHandle);\r
   ASSERT_EFI_ERROR(Status);\r
   Print(L"reopen file - pass\r\n");\r
 \r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
@@ -163,9 +193,9 @@ UefiMain (
   ASSERT_EFI_ERROR(Status);\r
   Print(L"size of empty - pass\r\n");\r
 \r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT(Status == EFI_NOT_FOUND);\r
@@ -181,23 +211,23 @@ UefiMain (
   Status = ShellDeleteFile(&FileHandle);\r
   ASSERT_EFI_ERROR(Status);\r
   Print(L"Directory create - pass\r\n");\r
-  \r
+\r
   // FindFirst and FindNext\r
   StrCpy(FileName, L"testDir");\r
   Status = ShellCreateDirectory(FileName, &FileHandle);\r
   Status = ShellCloseFile(&FileHandle);\r
   StrCat(FileName, L"\\File.txt");\r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
   Status = ShellCloseFile(&FileHandle);\r
   StrCpy(FileName, L"testDir");\r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
@@ -211,7 +241,7 @@ UefiMain (
   ASSERT(NoFile == FALSE);\r
   Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r
   ASSERT_EFI_ERROR(Status);\r
-  /// @todo - why is NoFile never set? limitation of NT32 file system?\r
+  ///@todo - why is NoFile never set? limitation of NT32 file system?\r
   Status = ShellDeleteFile(&FileHandle);\r
   ASSERT(Status == RETURN_WARN_DELETE_FAILURE);\r
   Print(L"FindFirst - pass\r\n");\r
@@ -234,18 +264,18 @@ UefiMain (
 \r
   // now delete that file and that directory\r
   StrCat(FileName, L"\\File.txt");\r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   ASSERT_EFI_ERROR(Status);\r
   Status = ShellDeleteFile(&FileHandle);\r
   StrCpy(FileName, L"testDir");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = ShellOpenFileByName(FileName, \r
-                               &FileHandle, \r
-                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r
+  Status = ShellOpenFileByName(FileName,\r
+                               &FileHandle,\r
+                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,\r
                                0\r
                                );\r
   Status = ShellDeleteFile(&FileHandle);\r
@@ -253,7 +283,7 @@ UefiMain (
 \r
   // get environment variable\r
   // made for testing under nt32\r
-  ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f8:\\efi\\tools;f8:\\efi\\boot;f8:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);\r
+  ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);\r
   Print(L"ShellGetEnvironmentVariable - pass\r\n");\r
 \r
   // set environment variable\r
@@ -266,21 +296,6 @@ UefiMain (
   ASSERT_EFI_ERROR(Status);\r
   // the pass printout for this is performed by EmptyApplication\r
   Print(L"\r\n");\r
-    \r
-  // command line param functions\r
-  Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);\r
-  // if you put an invalid parameter you SHOULD hit this assert.\r
-  ASSERT_EFI_ERROR(Status);\r
-  if (List) {\r
-    ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);\r
-    ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);\r
-    ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);\r
-    ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);\r
-\r
-    ShellCommandLineFreeVarList(List);\r
-  } else {\r
-    Print(L"param checking skipped.\r\n");\r
-  }\r
 \r
   // page break mode (done last so we can see the results)\r
   // we set this true at the begining of the program\r
@@ -322,4 +337,4 @@ done - ShellCommandLineFreeVarList
 done - ShellCommandLineGetFlag\r
 done - ShellCommandLineGetValue\r
 done - ShellCommandLineGetRawValue\r
-*/
\ No newline at end of file
+*/\r