FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testGetFieldValue.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011-2012 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 /* library includes */
8 #include <stdio.h>
9 /* cunit includes */
10 #include "CUnit/CUnit.h"
11 /* includes for files that will be tested */
12 #include <pkgagent.h>
13 
27 {
28  char *Sin = "hello name=larry, very good";
29  char Field[256];
30  int FieldMax = 256;
31  char Value[1024];
32  int ValueMax = 1024;
33  char Separator = '=';
34  char *predictValue = "name=larry, very good";
35  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
36  //printf("test_GetFieldValue_normal Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
37  CU_ASSERT_TRUE(!strcmp(Result, predictValue));
38 }
39 
48 {
49  char *Sin = "";
50  char Field[256];
51  int FieldMax = 256;
52  char Value[1024];
53  int ValueMax = 1024;
54  char Separator = '=';
55  char *predictValue = NULL;
56  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
57  //printf("test_GetFieldValue_sin_is_null Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
58  CU_ASSERT_EQUAL(Result, predictValue);
59 }
60 
69 {
70  char *Sin = "name=larry, very good";
71  char Field[256];
72  int FieldMax = 256;
73  char Value[1024];
74  int ValueMax = 1024;
75  char *predictField = "name";
76  char *predictValue = "=larry, very good";
77  char Separator = '\0';
78  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
79  //printf("test_GetFieldValue_noseparator Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
80  CU_ASSERT_TRUE(!strcmp(Result, predictValue));
81  CU_ASSERT_TRUE(!strcmp(Field, predictField));
82 }
83 
87 CU_TestInfo testcases_GetFieldValue[] = {
88  {"Testing GetFieldValue, paramters are normal:", test_GetFieldValue_normal},
89  {"Testing GetFieldValue, no separator:", test_GetFieldValue_noseparator},
90  {"Testing GetFieldValue,sin is null:", test_GetFieldValue_sin_is_null},
91  CU_TEST_INFO_NULL
92 };
93 
char * GetFieldValue(char *Sin, char *Field, int FieldMax, char *Value, int ValueMax)
Given a string that contains field='value' pairs, save the items.
Definition: finder.c:414
pkgagent header
void test_GetFieldValue_sin_is_null()
test case for input parameter is NULL
void test_GetFieldValue_noseparator()
test case for don't set input separator
void test_GetFieldValue_normal()
test case for input parameter is normal
CU_TestInfo testcases_GetFieldValue[]
testcases for function GetFieldValue
static int Result
Result of calls.
Definition: test_CopyFile.c:17