Refine tabs; Add utils functions; Update document

This commit is contained in:
2023-03-17 11:37:53 +08:00
parent 14d2e6e38c
commit c4b311e980
4 changed files with 161 additions and 21 deletions

81
entry.c
View File

@@ -2,11 +2,11 @@
#include "pine-ini.h"
void test_PineIni_StringTrim() {
const char *origin;
const char *origin;
char buf[100];
// case 1
origin = "123";
origin = "123";
strcpy(buf, origin);
printf("<%s> : <%s>\n", origin, PineIni_StringTrim(buf));
@@ -32,7 +32,7 @@ void test_PineIni_StringTrim() {
}
void test_PineIni_StringRemoveQuotes() {
const char *origin;
const char *origin;
char buf[100];
// case 1
@@ -173,6 +173,78 @@ void test_Ini_Param_Exceed() {
test_Ini(iniText);
}
void test_Ini_Get_Value() {
const char* iniText =
"vtargetFps=10\r\n"
"[mount]\r\n"
"root=card0\r\n"
"max_read=1024\r\n"
"[file]\r\n"
"ext=k3v\r\n";
PineIniError errorRet;
PineIniFile* iniResult;
PineIniSection* section;
char* sectionName;
char* key;
const char* szValue;
int intValue;
iniResult = PineIni_Parse(iniText, &errorRet);
// Test: get from ini file
// section - exist
// key - exist
sectionName = "mount";
key = "root";
szValue = PineIni_GetString(iniResult, sectionName, key, "fls0");
printf("Get String from <%s>.<%s> = %s\n", sectionName, key, szValue);
// Test: get from ini file
// section - exist
// key - not exist
sectionName = "mount";
key = "alt_root";
szValue = PineIni_GetString(iniResult, sectionName, key, "fls0");
printf("Get String from <%s>.<%s> = %s\n", sectionName, key, szValue);
// Test: get from ini file
// section - not exist
sectionName = "app-info";
key = "author";
szValue = PineIni_GetString(iniResult, sectionName, key, "anderain");
printf("Get String from <%s>.<%s> = %s\n", sectionName, key, szValue);
sectionName = "file";
section = PineIni_Find(iniResult, sectionName);
// Test: get from section
// key - exist
key = "ext";
szValue = PineIni_GetString(iniResult, sectionName, key, "k2v");
printf("Get String from <%s>.<%s> = %s\n", sectionName, key, szValue);
// Test: get from section
// key - not exist
key = "default_play";
szValue = PineIni_GetString(iniResult, sectionName, key, "video");
printf("Get String from <%s>.<%s> = %s\n", sectionName, key, szValue);
// Test: get int value
sectionName = "mount";
key = "max_read";
intValue = PineIni_GetInt(iniResult, sectionName, key, 100);
printf("Get Integer from <%s>.<%s> = %d\n", sectionName, key, intValue);
// Test: get int value
sectionName = "mount";
key = "min_read";
intValue = PineIni_GetInt(iniResult, sectionName, key, 1);
printf("Get Integer from <%s>.<%s> = %d\n", sectionName, key, intValue);
PineIni_Destory(iniResult);
}
void PutsTitle(const char* title) {
int padding = 6;
int length = strlen(title) + padding * 2;
@@ -217,6 +289,9 @@ int main(int argc, char* argv) {
PutsTitle("Test: Ini Success");
test_Ini_Success();
PutsTitle("Test: Get value from INI");
test_Ini_Get_Value();
PutsTitle("Test completed!");
return 0;