#include <stdio.h> #include <string.h> #include <stdlib.h> #include "at_parse.h" /* at_parse_*() */ #include "mutils.h" /* ITEMS_OF() */ int ok = 0; int faults = 0; int test_strcmp(const char *pa, const char *pb) { int retval; if (pa == NULL) pa = ""; if (pb == NULL) pb = ""; retval = strcmp(pa,pb); if (retval != 0) { int x = 0; while (pa[x] == pb[x] && pa[x] != 0) { x++; } printf("String '%s' and '%s' differs at " "offset %d '%c' != '%c'\n", pa, pb, x, pa[x], pb[x]); } return (retval); } #/* */ void test_parse_cnum() { static const struct test_case { const char * input; const char * result; } cases[] = { { "+CNUM: \"*Subscriber Number\",\"+79139131234\",145", "+79139131234" }, { "+CNUM: \"Subscriber Number\",\"\",145", "" }, { "+CNUM: \"Subscriber Number\",,145", "" }, { "+CNUM: \"\",\"+79139131234\",145", "+79139131234" }, { "+CNUM: ,\"\",145", "" }, { "+CNUM: ,,145", "" }, { "+CNUM: \"\",+79139131234\",145", "+79139131234" }, { "+CNUM: \"\",+79139131234,145", "+79139131234" }, }; unsigned idx = 0; char * input; const char * res; const char * msg; for(; idx < ITEMS_OF(cases); ++idx) { input = strdup(cases[idx].input); fprintf(stderr, "%s(\"%s\")...", "at_parse_cnum", input); res = at_parse_cnum(input); if(test_strcmp(res, cases[idx].result) == 0) { msg = "OK"; ok++; } else { msg = "FAIL"; faults++; } fprintf(stderr, " = \"%s\"\t%s\n", res, msg); free(input); } fprintf(stderr, "\n"); } #/* */ void test_parse_cops() { static const struct test_case { const char * input; const char * result; } cases[] = { { "+COPS: 0,0,\"TELE2\",0", "TELE2" }, { "+COPS: 0,0,\"TELE2,0", "TELE2" }, { "+COPS: 0,0,TELE2,0", "TELE2" }, }; unsigned idx = 0; char * input; const char * res; const char * msg; for(; idx < ITEMS_OF(cases); ++idx) { input = strdup(cases[idx].input); fprintf(stderr, "%s(\"%s\")...", "at_parse_cops", input); res = at_parse_cops(input); if(test_strcmp(res, cases[idx].result) == 0) { msg = "OK"; ok++; } else { msg = "FAIL"; faults++; } fprintf(stderr, " = \"%s\"\t%s\n", res, msg); free(input); } fprintf(stderr, "\n"); }
int CardDevice::at_response_cops(char* str, size_t len) { char* provider_name = at_parse_cops(str, len); if(provider_name) { m_provider_name = provider_name; return 0; } m_provider_name = "NONE"; return -1; }
static inline int at_response_cops (pvt_t* pvt, char* str, size_t len) { char* provider_name = at_parse_cops (pvt, str, len); if (provider_name) { ast_string_field_set (pvt, provider_name, provider_name); return 0; } ast_string_field_set (pvt, provider_name, "NONE"); return -1; }