diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/1-1.c new file mode 100644 index 00000000000..dec71d3972f --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/1-1.c @@ -0,0 +1,61 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * This function will convert the initial portion of the string pointed to by + * nptr to a type long. + * + * method: + * -Convert LONG_MAX to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function. + * -Compare the return value with LONG_MAX. + * +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/1-1.c" +#define MAX_ARRAY_SIZE 50 + +int main(void) +{ + char nptr[MAX_ARRAY_SIZE]; + long result; + int char_written; + errno = 0; + + /* convert integer to string */ + char_written = sprintf(nptr, "%ld", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + + errno = 0; + result = strtol(nptr, NULL, 10); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + exit(PTS_FAIL); + } + + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, String conversion to long got failed, Expected: %ld," + " But got: %ld.\n", LONG_MAX, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/10-1.c new file mode 100644 index 00000000000..ae663eabb4b --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/10-1.c @@ -0,0 +1,42 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If no conversion could be performed: + * 0 will be returned. + * + * method: + * -Take a string with first invalid byte, for octal integer. + * -Convert it to long using strtol() + * with base 8. + * -check whether the result is 0. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/10-1.c" + +int main(void) +{ + char nptr[] = "H1234"; + long result; + + result = strtol(nptr, NULL, 8); + if (result == 0) { + printf(TNAME " Test passed. Returned zero as expected.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed. Expected: %d ,But got: %ld\n", 0, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/11-1.c new file mode 100644 index 00000000000..11868f500d5 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/11-1.c @@ -0,0 +1,57 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the value of base is not supported: + * 0 will be returned and errno will be set to [EINVAL] + * + * method: + * -Convert LONG_MAX to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function + * with base which is not supported by strtol(<2 and >36) + * -Compare the return value and errno. + * +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/11-1.c" +#define MAX_ARRAY_SIZE 50 + +int main(void) +{ + char nptr[MAX_ARRAY_SIZE] = {}; + long result; + int char_written; + errno = 0; + + /* convert integer to string */ + char_written = sprintf(nptr, "%ld", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + + errno = 0; + result = strtol(nptr, NULL, 37); + if (result == 0 && errno == EINVAL) { + printf(TNAME " Test passed, conversion error occured for unsupported base.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, Expected result: %d, But obtained: %ld" + " and Expected errno: %d, But obtained errno: %d\n" + , 0, result, EINVAL, errno); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/12-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/12-1.c new file mode 100644 index 00000000000..a2c5883bf1b --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/12-1.c @@ -0,0 +1,65 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the correct value is outside the range of representable values: + * {LONG_MIN}, {LONG_MAX}, will be returned (according to the sign + * of the value), and errno set to [ERANGE]. + * + * method: + * -Define a string which has an integer greater + * than LONG_MAX range. + * -Convert string to long using strtol() function. + * -Compare the return value with LONG_MAX and check errno. + * -Define a string which has an integer lesser + * than LONG_MIN range. + * -Convert string to long using strtol() function. + * -Compare the return value with LONG_MIN and check errno. + * +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/12-1.c" + +int main(void) +{ + char nptr_1[] = "922337203685477580798"; + char nptr_2[] = "-922337203685477580798"; + long result; + errno = 0; + + result = strtol(nptr_1, NULL, 10); + if (result == LONG_MAX && errno == ERANGE) { + printf(TNAME " Test passed, LONG_MAX is returned and errno is set to indicate " + "out of range error.\n"); + } else { + printf(TNAME " Test Failed, Expected result: %ld, But got result: %ld\n" + " \t\t\t and Expected errno: %d, But obtained errno: %d\n" + , LONG_MAX, result, ERANGE, errno); + exit(PTS_FAIL); + } + + errno = 0; + result = strtol(nptr_2, NULL, 10); + if (result == LONG_MIN && errno == ERANGE) { + printf(TNAME " Test passed, LONG_MIN is returned and errno is set to indicate " + "out of range error.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, Expected result: %ld, But got result: %ld\n" + "\t\t\t and Expected errno: %d, But obtained errno: %d\n", + LONG_MIN, result, ERANGE, errno); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/2-1.c new file mode 100644 index 00000000000..ee1f45a391d --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/2-1.c @@ -0,0 +1,71 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the input string is empty or consists entirely of white-space characters, + * or if the first non-white-space character is other than a sign or a permissible + * letter or digit: + * The subject sequence will contain no characters. + * A subject sequence is interpreted as an integer represented in some radix + * determined by the value of base. + * + * method: + * -Take a input string with first non-white-space character + * other than permissible letter. + * -Convert string to long using strtol() function + * with base 10. + * -Compare the value stored in nptr and endptr. + * -Repeat above steps for empty string and string + * having white-space characters with base 8 and 16 + * respectively. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/2-1.c" + +int main(void) +{ + char nptr_1[] = "Z123"; + char nptr_2[] = {}; + char nptr_3[] = " "; + char *endptr = NULL; + + /* Check with first non-white-space character other than permissible letter */ + strtol(nptr_1, &endptr, 10); + if (nptr_1 == endptr) { + printf(TNAME " Test passed.\n"); + } else { + printf(TNAME " Test Failed. Expected: %s, But got: %s.\n", nptr_1, endptr); + exit(PTS_FAIL); + } + + /* Check with empty string */ + strtol(nptr_2, &endptr, 8); + if (nptr_2 == endptr) { + printf(TNAME " Test passed.\n"); + } else { + printf(TNAME " Test Failed. Expected: %s, But got: %s.\n", nptr_2, endptr); + exit(PTS_FAIL); + } + + /* Check with white-space characters */ + strtol(nptr_3, &endptr, 16); + if (nptr_3 == endptr) { + printf(TNAME " Test passed.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed. Expected: %s, But got: %s.\n", nptr_3, endptr); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/3-1.c new file mode 100644 index 00000000000..69910c1d439 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/3-1.c @@ -0,0 +1,116 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the subject sequence has the expected form and the value of base is 0: + * The sequence of characters starting with the first digit will be + * interpreted as an integer constant. + * + * method: + * Demical: + * -Convert LONG_MAX to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function with base 0. + * -Compare the return value with LONG_MAX. + * Octal and Hexadecimal: + * -Repeat the same steps for octal and hexadecimal with one + * extra step to add "0" and "0x" to input string(nptr) + * for octal and hexadecimal respectively. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/3-1.c" +#define MAX_ARRAY_SIZE 20 + +int main(void) +{ + char *nptr = malloc(MAX_ARRAY_SIZE); + long result; + int char_written; + char base_hex[] = "0x"; + char base_oct[] = "0"; + + /* For decimal constant */ + errno = 0; + char_written = sprintf(nptr, "%ld", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + free(nptr); + exit(PTS_UNRESOLVED); + } + errno = 0; + result = strtol(nptr, NULL, 0); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + free(nptr); + exit(PTS_FAIL); + } + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long decimal integer.\n"); + free(nptr); + } else { + printf(TNAME " Test Failed, String conversion into long decimal integer got " + "failed, Expected: %ld, But got: %ld.\n", LONG_MAX, result); + free(nptr); + exit(PTS_FAIL); + } + + /* For hexadecimal constant */ + errno = 0; + char_written = sprintf(nptr, "%lx", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + nptr = strcat(base_hex, nptr); + errno = 0; + result = strtol(nptr, NULL, 0); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + exit(PTS_FAIL); + } + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long hexadecimal integer.\n"); + } else { + printf(TNAME " Test Failed, String conversion into long hexadecimal integer got " + "failed, Expected: %lx, But got: %lx.\n", LONG_MAX, result); + exit(PTS_FAIL); + } + + /* For octal constant */ + errno = 0; + char_written = sprintf(nptr, "%lo", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + nptr = strcat(base_oct, nptr); + errno = 0; + result = strtol(nptr, NULL, 0); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + exit(PTS_FAIL); + } + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long octal integer.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, String conversion into octal integer got failed," + " Expected: %lo, But got: %lo.\n", LONG_MAX, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/4-1.c new file mode 100644 index 00000000000..a23ecdb504a --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/4-1.c @@ -0,0 +1,160 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the subject sequence has the expected form and the value of base is + * between 2 and 36: + * It will be used as the base for conversion. + * + * method: + * Demical, octal, hexadecimal: + * -Convert LONG_MAX to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function with base given. + * -Compare the return value with LONG_MAX. + * -Repeat the same steps for other base values. + * For base 9,13 and 36: + * -Define a string constant with value permissible for base 9. + * -Define expected value in decimal for the value in defined string. + * -Convert string to long using strtol() function with base 9. + * -Compare return value and expected value. + * -Repeat above steps for base 13 and 36. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/4-1.c" +#define MAX_ARRAY_SIZE 20 + +int main(void) +{ + char *nptr = malloc(MAX_ARRAY_SIZE); + long result; + int char_written; + char *nptr_1 = "234"; + long expected_res_base_9 = 193; + char *nptr_2 = "A567"; + long expected_res_base_13 = 22900; + char *nptr_3 = "Z678"; + long expected_res_base_36 = 1640996; + + /* For decimal constant */ + errno = 0; + char_written = sprintf(nptr, "%ld", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + errno = 0; + result = strtol(nptr, NULL, 10); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long decimal integer.\n"); + } else { + printf(TNAME " Test Failed, String conversion into long decimal integer got " + "failed, Expected: %ld, But got: %ld.\n", LONG_MAX, result); + exit(PTS_FAIL); + } + + /* For hexadecimal constant */ + errno = 0; + char_written = sprintf(nptr, "%lx", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + errno = 0; + result = strtol(nptr, NULL, 16); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long hexadecimal integer.\n"); + } else { + printf(TNAME " Test Failed, String conversion into long hexadecimal integer got " + "failed, Expected: %lx, But got: %lx.\n", LONG_MAX, result); + exit(PTS_FAIL); + } + + /* For octal constant */ + errno = 0; + char_written = sprintf(nptr, "%lo", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME " Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + errno = 0; + result = strtol(nptr, NULL, 8); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + if (result == LONG_MAX) { + printf(TNAME " Test passed, String got converted into long octal integer.\n"); + } else { + printf(TNAME " Test Failed, String conversion into octal integer got " + "failed, Expected: %lo, But got: %lo.\n", LONG_MAX, result); + exit(PTS_FAIL); + } + + /* For base 9 */ + errno = 0; + result = strtol(nptr_1, NULL, 9); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + if (result == expected_res_base_9) { + printf(TNAME " Test passed, String got converted into long integer of base 9.\n"); + } else { + printf(TNAME " Test Failed, String conversion into integer of base 9 got " + "failed, Expected: %ld, But got: %ld.\n", expected_res_base_9, result); + exit(PTS_FAIL); + } + + /* For base 13 */ + errno = 0; + result = strtol(nptr_2, NULL, 13); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + if (result == expected_res_base_13) { + printf(TNAME " Test passed, String got converted into long integer of base 13.\n"); + } else { + printf(TNAME " Test Failed, String conversion into integer of base 13 got " + "failed, Expected: %ld, But got: %ld.\n", expected_res_base_13, result); + exit(PTS_FAIL); + } + + /* For base36 */ + errno = 0; + result = strtol(nptr_3, NULL, 36); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), errno = %d\n", errno); + exit(PTS_FAIL); + } + if (result == expected_res_base_36) { + printf(TNAME " Test passed, String got converted into long integer of base 36.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, String conversion into integer of base 36 got " + "failed, Expected: %ld, But got: %ld.\n", expected_res_base_36, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/5-1.c new file mode 100644 index 00000000000..4ce8b8ffba3 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/5-1.c @@ -0,0 +1,61 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * If the subject sequence begins with a 'hyphen-minus': + * The value resulting from the conversion will be negated. + * + * method: + * -Convert LONG_MIN to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function. + * -Compare the return value with negative LONG_MIN. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/5-1.c" +#define MAX_ARRAY_SIZE 50 + +int main(void) +{ + char nptr[MAX_ARRAY_SIZE] = {}; + long result; + int char_written; + errno; + + /* convert integer to string */ + /* Considering LONG_MIN as it starts minus(-) */ + char_written = sprintf(nptr, "%ld", LONG_MIN); + if (char_written != strlen(nptr)) { + printf(TNAME "Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + + errno = 0; + result = strtol(nptr, NULL, 10); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + exit(PTS_FAIL); + } + + if (result == LONG_MIN) { + printf(TNAME " Test passed, String got converted into long.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, String conversion to long got failed, Expected: %ld" + " ,But got: %ld\n", LONG_MIN, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/6-1.c new file mode 100644 index 00000000000..0677f7abdab --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/6-1.c @@ -0,0 +1,55 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * A pointer to the final string will be stored in the object pointed + * to by endptr, provided that endptr is not a null pointer. + * A final string is one or more unrecognized characters, including the + * terminating NUL character of the input string. + * method: + * -Define a string which has half of the string valid characters + * and other half string as invalid characters, for base 10. + * -Define pos as the position of first invalid character in + * the string, for base 10. + * -Use strtol() to convert string to long int with base10. + * -Compare the endptr and nptr+pos. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/6-1.c" + +int main(void) +{ + char *nptr = "1234F112"; + char *endptr = NULL; + int pos = 4; + long result; + errno = 0; + + result = strtol(nptr, &endptr, 10); + if (result == 0) { + printf(TNAME " Unexpected return from strtol(), expected: %ld, But got: %ld," + " errno = %d\n", LONG_MAX, result, errno); + exit(PTS_FAIL); + } + + if (endptr == nptr + pos) { + printf(TNAME " Test passed.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed,Expected nptr: %p" + " ,But got nptr: %p\n", nptr + pos, endptr); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/7-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/strtol/7-1.sh new file mode 100755 index 00000000000..f2b10cb8d8f --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/7-1.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# This file is licensed under the GPL license. For the full content +# of this license, see the COPYING file at the top level of this +# source tree. + +# assertion: +# If the subject sequence is empty or does not have the expected form: +# No conversion is performed and the value of nptr will be stored in +# the object pointed to by endptr, provided that endptr is not a +# null pointer. + +# This is tested implicitly via assertion 6. + + echo "Tested implicitly via assertion 6." + exit 0 + diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/8-1.c b/testcases/open_posix_testsuite/conformance/interfaces/strtol/8-1.c new file mode 100644 index 00000000000..e61ef4279b0 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/8-1.c @@ -0,0 +1,61 @@ +/* + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + */ + +/* + * assertion: + * This function will not change the setting of errno if successful. + * + * method: + * -Convert LONG_MAX to string using sprintf + * as strtol() needs input in string format. + * -Convert string to long using strtol() function. + * -Compare the return value with LONG_MAX. + * -If comparison is successfull, then check errno value. +*/ + +#include +#include +#include +#include +#include +#include +#include "posixtest.h" + +#define TNAME "strtol/8-1.c" +#define MAX_ARRAY_SIZE 50 + +int main(void) +{ + char nptr[MAX_ARRAY_SIZE] = { }; + long result; + int char_written; + errno = 0; + + /* convert integer to string */ + char_written = sprintf(nptr, "%ld", LONG_MAX); + if (char_written != strlen(nptr)) { + printf(TNAME "Error at sprintf(), errno = %d\n", errno); + exit(PTS_UNRESOLVED); + } + + errno = 0; + result = strtol(nptr, NULL, 10); + + if (result == LONG_MAX) { + if (errno == 0) { + printf(TNAME " Test passed, errno is not changed.\n"); + exit(PTS_PASS); + } else { + printf(TNAME " Test Failed, errno is changed. Expected errno: %d," + " Obtained: %d.\n", 0, errno); + exit(PTS_FAIL); + } + } else { + printf(TNAME " Unexpected return from strtol. Expected: %ld," + " But got: %ld\n", LONG_MAX, result); + exit(PTS_FAIL); + } +} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/9-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/strtol/9-1.sh new file mode 100755 index 00000000000..13eb6375197 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/9-1.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# This file is licensed under the GPL license. For the full content +# of this license, see the COPYING file at the top level of this +# source tree. + +# assertion: +# Upon successful completion, this function will return the converted value, if any. + +# This is tested implicitly via assertion 1. + + echo "Tested implicitly via assertion 1." + exit 0 + diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/assertions.xml b/testcases/open_posix_testsuite/conformance/interfaces/strtol/assertions.xml new file mode 100644 index 00000000000..9d3fc2f6a96 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/assertions.xml @@ -0,0 +1,60 @@ + + + This function will convert the initial portion of the string pointed to by + nptr to a type long. + + + If the input string is empty or consists entirely of white-space characters, + or if the first non-white-space character is other than a sign or a permissible + letter or digit: + The subject sequence will contain no characters. + A subject sequence is interpreted as an integer represented in some radix + determined by the value of base. + + + If the subject sequence has the expected form and the value of base is 0: + The sequence of characters starting with the first digit will be + interpreted as an integer constant. + + + If the subject sequence has the expected form and the value of base is + between 2 and 36: + It will be used as the base for conversion. + + + If the subject sequence begins with a 'hyphen-minus': + The value resulting from the conversion will be negated. + + + A pointer to the final string will be stored in the object pointed + to by endptr, provided that endptr is not a null pointer. + A final string is one or more unrecognized characters, including the + terminating NUL character of the input string. + + + If the subject sequence is empty or does not have the expected form: + No conversion is performed and the value of nptr will be stored in + the object pointed to by endptr, provided that endptr is not a + null pointer. + + + This function will not change the setting of errno if successful. + + + Upon successful completion, this function will return the converted value, if any. + + + If no conversion could be performed: + 0 will be returned and errno may be set to [EINVAL]. + + + If the value of base is not supported: + 0 will be returned and errno will be set to [EINVAL]. + + + If the correct value is outside the range of representable values: + {LONG_MIN}, {LONG_MAX}, will be returned (according to the sign + of the value), and errno set to [ERANGE]. + + + diff --git a/testcases/open_posix_testsuite/conformance/interfaces/strtol/coverage.txt b/testcases/open_posix_testsuite/conformance/interfaces/strtol/coverage.txt new file mode 100644 index 00000000000..e3d2a5ecea1 --- /dev/null +++ b/testcases/open_posix_testsuite/conformance/interfaces/strtol/coverage.txt @@ -0,0 +1,15 @@ +This file defines the coverage for the strtol() function testing + + Assertion Status + 1 YES + 2 YES + 3 YES + 4 YES + 5 YES + 6 YES + 7 YES + 8 YES + 9 YES + 10 YES + 11 YES + 12 YES