FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testGetFieldValue.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2011-2012 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *********************************************************************/
17 
18 /* library includes */
19 #include <stdio.h>
20 /* cunit includes */
21 #include "CUnit/CUnit.h"
22 /* includes for files that will be tested */
23 #include <pkgagent.h>
24 
38 {
39  char *Sin = "hello name=larry, very good";
40  char Field[256];
41  int FieldMax = 256;
42  char Value[1024];
43  int ValueMax = 1024;
44  char Separator = '=';
45  char *predictValue = "name=larry, very good";
46  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
47  //printf("test_GetFieldValue_normal Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
48  CU_ASSERT_TRUE(!strcmp(Result, predictValue));
49 }
50 
59 {
60  char *Sin = "";
61  char Field[256];
62  int FieldMax = 256;
63  char Value[1024];
64  int ValueMax = 1024;
65  char Separator = '=';
66  char *predictValue = NULL;
67  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
68  //printf("test_GetFieldValue_sin_is_null Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
69  CU_ASSERT_EQUAL(Result, predictValue);
70 }
71 
80 {
81  char *Sin = "name=larry, very good";
82  char Field[256];
83  int FieldMax = 256;
84  char Value[1024];
85  int ValueMax = 1024;
86  char *predictField = "name";
87  char *predictValue = "=larry, very good";
88  char Separator = '\0';
89  char *Result = GetFieldValue(Sin, Field, FieldMax, Value, ValueMax, Separator);
90  //printf("test_GetFieldValue_noseparator Result is:%s, field is: %s, value is:%s\n", Result, Field, Value);
91  CU_ASSERT_TRUE(!strcmp(Result, predictValue));
92  CU_ASSERT_TRUE(!strcmp(Field, predictField));
93 }
94 
98 CU_TestInfo testcases_GetFieldValue[] = {
99  {"Testing GetFieldValue, paramters are normal:", test_GetFieldValue_normal},
100  {"Testing GetFieldValue, no separator:", test_GetFieldValue_noseparator},
101  {"Testing GetFieldValue,sin is null:", test_GetFieldValue_sin_is_null},
102  CU_TEST_INFO_NULL
103 };
104 
CU_TestInfo testcases_GetFieldValue[]
testcases for function GetFieldValue
static int Result
Result of calls.
Definition: test_CopyFile.c:28
char * GetFieldValue(char *Sin, char *Field, int FieldMax, char *Value, int ValueMax)
Given a string that contains field=&#39;value&#39; pairs, save the items.
Definition: finder.c:425
void test_GetFieldValue_sin_is_null()
test case for input parameter is NULL
void test_GetFieldValue_noseparator()
test case for don&#39;t set input separator
pkgagent header
void test_GetFieldValue_normal()
test case for input parameter is normal