Use PROGNAME

This commit is contained in:
Pierre Pronchery 2016-08-14 19:57:38 +02:00
parent cd4cb128f0
commit a2f5d12e1e

View File

@ -19,20 +19,32 @@
#include <stdio.h>
#include "System/string.h"
#ifndef PROGNAME
# define PROGNAME "string"
#endif
/* prototypes */
static int _test(String * s);
static int _test2(String const * string, String * rtrim, int rcount);
static int _test3(String const * string, String * ltrim, int lcount);
static int _test4(String const * string, String * trim, int count);
/* functions */
/* test */
static int _test(char const * progname, String * s)
static int _test(String * s)
{
size_t len;
size_t i;
/* string_get_length */
printf("%s: Testing %s\n", progname, "string_get_length()");
printf("%s: Testing %s\n", PROGNAME, "string_get_length()");
if((len = string_get_length(s)) == 0)
return 2;
printf("\"%s\" => %zu\n", s, len);
/* string_clear */
printf("%s: Testing %s\n", progname, "string_clear()");
printf("%s: Testing %s\n", PROGNAME, "string_clear()");
string_clear(s);
for(i = 0; i <= len; i++)
if(s[i] != '\0')
@ -42,8 +54,7 @@ static int _test(char const * progname, String * s)
/* test2 */
static int _test2(char const * progname, String const * string, String * rtrim,
int rcount)
static int _test2(String const * string, String * rtrim, int rcount)
{
int ret = 0;
String * s;
@ -52,10 +63,10 @@ static int _test2(char const * progname, String const * string, String * rtrim,
if((s = string_new(string)) == NULL)
return -1;
/* string_rtrim */
printf("%s: Testing %s\n", progname, "string_rtrim()");
printf("%s: Testing %s\n", PROGNAME, "string_rtrim()");
if((res = string_rtrim(s, rtrim)) != rcount)
{
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", progname,
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", PROGNAME,
string, rtrim, res, rcount);
ret = 8;
}
@ -65,8 +76,7 @@ static int _test2(char const * progname, String const * string, String * rtrim,
/* test3 */
static int _test3(char const * progname, String const * string, String * ltrim,
int lcount)
static int _test3(String const * string, String * ltrim, int lcount)
{
int ret = 0;
String * s;
@ -75,10 +85,10 @@ static int _test3(char const * progname, String const * string, String * ltrim,
if((s = string_new(string)) == NULL)
return -1;
/* string_rtrim */
printf("%s: Testing %s\n", progname, "string_ltrim()");
printf("%s: Testing %s\n", PROGNAME, "string_ltrim()");
if((res = string_ltrim(s, ltrim)) != lcount)
{
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", progname,
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", PROGNAME,
string, ltrim, res, lcount);
ret = 16;
}
@ -88,8 +98,7 @@ static int _test3(char const * progname, String const * string, String * ltrim,
/* test4 */
static int _test4(char const * progname, String const * string, String * trim,
int count)
static int _test4(String const * string, String * trim, int count)
{
int ret = 0;
String * s;
@ -98,10 +107,10 @@ static int _test4(char const * progname, String const * string, String * trim,
if((s = string_new(string)) == NULL)
return -1;
/* string_trim */
printf("%s: Testing %s\n", progname, "string_trim()");
printf("%s: Testing %s\n", PROGNAME, "string_trim()");
if((res = string_trim(s, trim)) != count)
{
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", progname,
printf("%s: %s, %s, %d: Test failed (expected: %d)\n", PROGNAME,
string, trim, res, count);
ret = 32;
}
@ -120,48 +129,48 @@ int main(int argc, char * argv[])
/* test */
if((s = string_new(argv[0])) == NULL)
return 2;
ret |= _test(argv[0], s);
ret |= _test(s);
string_delete(s);
if((s = string_new_format("%s", argv[0])) == NULL)
return 2;
ret |= _test(argv[0], s);
ret |= _test(s);
string_delete(s);
/* test2 */
ret |= _test2(argv[0], "", NULL, 0);
ret |= _test2(argv[0], " ", NULL, 1);
ret |= _test2(argv[0], "", "", 0);
ret |= _test2(argv[0], "Y", "Y", 1);
ret |= _test2(argv[0], "YYYY", NULL, 0);
ret |= _test2(argv[0], "YYYY", "", 0);
ret |= _test2(argv[0], "YYYY", "Y", 4);
ret |= _test2(argv[0], "ZYYYY", "Z", 0);
ret |= _test2(argv[0], "YYYYZ", "Z", 1);
ret |= _test2(argv[0], "YYYYZZ", "Z", 2);
ret |= _test2(argv[0], "YYYYZZ", "YZ", 6);
ret |= _test2("", NULL, 0);
ret |= _test2(" ", NULL, 1);
ret |= _test2("", "", 0);
ret |= _test2("Y", "Y", 1);
ret |= _test2("YYYY", NULL, 0);
ret |= _test2("YYYY", "", 0);
ret |= _test2("YYYY", "Y", 4);
ret |= _test2("ZYYYY", "Z", 0);
ret |= _test2("YYYYZ", "Z", 1);
ret |= _test2("YYYYZZ", "Z", 2);
ret |= _test2("YYYYZZ", "YZ", 6);
/* test3 */
ret |= _test3(argv[0], "", NULL, 0);
ret |= _test3(argv[0], " ", NULL, 1);
ret |= _test3(argv[0], "", "", 0);
ret |= _test3(argv[0], "Y", "Y", 1);
ret |= _test3(argv[0], "YYYY", NULL, 0);
ret |= _test3(argv[0], "YYYY", "", 0);
ret |= _test3(argv[0], "YYYY", "Y", 4);
ret |= _test3(argv[0], "YZZZZ", "Z", 0);
ret |= _test3(argv[0], "YZZZZ", "Y", 1);
ret |= _test3(argv[0], "YYZZZZ", "Y", 2);
ret |= _test3(argv[0], "YYYYZZ", "YZ", 6);
ret |= _test3("", NULL, 0);
ret |= _test3(" ", NULL, 1);
ret |= _test3("", "", 0);
ret |= _test3("Y", "Y", 1);
ret |= _test3("YYYY", NULL, 0);
ret |= _test3("YYYY", "", 0);
ret |= _test3("YYYY", "Y", 4);
ret |= _test3("YZZZZ", "Z", 0);
ret |= _test3("YZZZZ", "Y", 1);
ret |= _test3("YYZZZZ", "Y", 2);
ret |= _test3("YYYYZZ", "YZ", 6);
/* test4 */
ret |= _test4(argv[0], "", NULL, 0);
ret |= _test4(argv[0], " ", NULL, 1);
ret |= _test4(argv[0], "", "", 0);
ret |= _test4(argv[0], "Y", "Y", 1);
ret |= _test4(argv[0], "YYYY", NULL, 0);
ret |= _test4(argv[0], "YYYY", "", 0);
ret |= _test4(argv[0], "YYYY", "Y", 4);
ret |= _test4(argv[0], "YYYYZ", "Z", 1);
ret |= _test4(argv[0], "YYYYZZ", "Z", 2);
ret |= _test4(argv[0], "YYYYZZ", "YZ", 6);
ret |= _test4(argv[0], "ZZYYYYZZ", "YZ", 8);
ret |= _test4(argv[0], "ZZYYYYZZ", "Y", 0);
ret |= _test4("", NULL, 0);
ret |= _test4(" ", NULL, 1);
ret |= _test4("", "", 0);
ret |= _test4("Y", "Y", 1);
ret |= _test4("YYYY", NULL, 0);
ret |= _test4("YYYY", "", 0);
ret |= _test4("YYYY", "Y", 4);
ret |= _test4("YYYYZ", "Z", 1);
ret |= _test4("YYYYZZ", "Z", 2);
ret |= _test4("YYYYZZ", "YZ", 6);
ret |= _test4("ZZYYYYZZ", "YZ", 8);
ret |= _test4("ZZYYYYZZ", "Y", 0);
return ret;
}