|
| 1 | +/** |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0. |
| 4 | + */ |
| 5 | + |
| 6 | +package software.amazon.awssdk.crt.test; |
| 7 | + |
| 8 | +import org.junit.Test; |
| 9 | +import software.amazon.awssdk.crt.CRT; |
| 10 | + |
| 11 | +import static org.junit.Assert.*; |
| 12 | + |
| 13 | +/** |
| 14 | + * Test suite for static methods in CRT class. |
| 15 | + */ |
| 16 | +public class CrtStaticTest extends CrtTestFixture { |
| 17 | + |
| 18 | + public CrtStaticTest() { |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Test that AWS_CRT_SUCCESS (0) is not considered a transient error. |
| 23 | + */ |
| 24 | + @Test |
| 25 | + public void testAwsIsTransientErrorWithSuccess() { |
| 26 | + assertFalse("Success code should not be transient", CRT.awsIsTransientError(CRT.AWS_CRT_SUCCESS)); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Test that the method returns a valid boolean for various error codes. |
| 31 | + */ |
| 32 | + @Test |
| 33 | + public void testAwsIsTransientErrorWithVariousErrorCodes() { |
| 34 | + // Test with a range of error codes to ensure the method doesn't crash |
| 35 | + int[] testErrorCodes = {0, 1, 1024, 2048, 3072, 4096}; |
| 36 | + |
| 37 | + for (int errorCode : testErrorCodes) { |
| 38 | + // The method should return a valid boolean without throwing an exception |
| 39 | + boolean result = CRT.awsIsTransientError(errorCode); |
| 40 | + // Just verify the call completes successfully - the actual result depends on native implementation |
| 41 | + assertNotNull("Should return a valid boolean", Boolean.valueOf(result)); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Test that the method handles invalid error codes gracefully. |
| 47 | + */ |
| 48 | + @Test |
| 49 | + public void testAwsIsTransientErrorWithInvalidCodes() { |
| 50 | + // Test with invalid error codes |
| 51 | + assertFalse("Negative error code should not be transient", CRT.awsIsTransientError(-1)); |
| 52 | + assertFalse("Large error code should not be transient", CRT.awsIsTransientError(999999)); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Test awsLastError returns a valid error code. |
| 57 | + */ |
| 58 | + @Test |
| 59 | + public void testAwsLastError() { |
| 60 | + int lastError = CRT.awsLastError(); |
| 61 | + // The error code should be non-negative |
| 62 | + assertTrue("Last error should be non-negative", lastError >= 0); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Test awsErrorString returns a non-null string for valid error codes. |
| 67 | + */ |
| 68 | + @Test |
| 69 | + public void testAwsErrorString() { |
| 70 | + String errorString = CRT.awsErrorString(0); |
| 71 | + assertNotNull("Error string should not be null", errorString); |
| 72 | + |
| 73 | + // Test with a non-zero error code |
| 74 | + errorString = CRT.awsErrorString(1); |
| 75 | + assertNotNull("Error string should not be null", errorString); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Test awsErrorName returns a non-null string for valid error codes. |
| 80 | + */ |
| 81 | + @Test |
| 82 | + public void testAwsErrorName() { |
| 83 | + String errorName = CRT.awsErrorName(0); |
| 84 | + assertNotNull("Error name should not be null", errorName); |
| 85 | + |
| 86 | + // Test with a non-zero error code |
| 87 | + errorName = CRT.awsErrorName(1); |
| 88 | + assertNotNull("Error name should not be null", errorName); |
| 89 | + } |
| 90 | +} |
0 commit comments