TestLauncherTarget.mm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #import <XCTest/XCTest.h>
  9. #include <AzCore/IO/SystemFile.h>
  10. #include <AzCore/Utils/Utils.h>
  11. #include "aztestrunner.h"
  12. constexpr size_t s_maxArgCount = 8;
  13. constexpr size_t s_maxArgLength = 256;
  14. namespace AzTestRunner
  15. {
  16. void set_quiet_mode()
  17. {
  18. }
  19. const char* get_current_working_directory()
  20. {
  21. static char cwd_buffer[AZ_MAX_PATH_LEN] = { '\0' };
  22. AZ::Utils::ExecutablePathResult result = AZ::Utils::GetExecutableDirectory(cwd_buffer, AZ_ARRAY_SIZE(cwd_buffer));
  23. AZ_Assert(result == AZ::Utils::ExecutablePathResult::Success, "Error retrieving executable path");
  24. return static_cast<const char*>(cwd_buffer);
  25. }
  26. void pause_on_completion()
  27. {
  28. }
  29. }
  30. @interface TestLauncherTarget : XCTestCase
  31. @property(strong) NSArray* commandLineArgs;
  32. @property size_t argCount;
  33. @property bool testSuccessful;
  34. @end
  35. @implementation TestLauncherTarget
  36. -(void) setUp
  37. {
  38. NSLog(@"TEST STARTED");
  39. self.commandLineArgs = [[NSProcessInfo processInfo] arguments];
  40. self.argCount = [self.commandLineArgs count];
  41. self.testSuccessful = false;
  42. }
  43. -(void) tearDown
  44. {
  45. if (self.testSuccessful)
  46. {
  47. NSLog(@"TEST SUCCEEDED");
  48. }
  49. else
  50. {
  51. NSLog(@"TEST FAILED");
  52. }
  53. }
  54. -(void) testLibrary
  55. {
  56. char args[s_maxArgCount][s_maxArgLength] = { {'\0'} };
  57. char *argv[s_maxArgCount];
  58. size_t argc = self.argCount;
  59. for (size_t argIndex = 0; argIndex < s_maxArgCount && argIndex < argc; ++argIndex)
  60. {
  61. const char* arg = [self.commandLineArgs[argIndex] UTF8String];
  62. azstrncpy(args[argIndex], s_maxArgLength, arg, strlen(arg));
  63. argv[argIndex] = args[argIndex];
  64. }
  65. int status = AzTestRunner::wrapped_main(argc, argv);
  66. self.testSuccessful = (status == 0);
  67. XCTAssert(self.testSuccessful);
  68. }
  69. @end