summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2010-06-03 11:55:51 +0200
committerMichal Čihař <michal@cihar.com>2010-06-03 11:55:51 +0200
commit9e9e58b0758e385940418ad8b412a6a77d45941e (patch)
tree4468003cd66ccaba3e81fe04080c7b0df905e507 /tests
parent241730d63b033e865af4880a544bef455de6e6bb (diff)
Imported Upstream version 1.27.94
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt51
-rw-r--r--tests/at-creg-reply.c103
-rw-r--r--tests/at-creg/huawei.dump3
-rw-r--r--tests/at-creg/none.dump4
-rw-r--r--tests/at-creg/siemens.dump3
-rw-r--r--tests/inifile.c46
-rw-r--r--tests/inifiles/basic.ini6
-rw-r--r--tests/inifiles/comments.ini11
-rw-r--r--tests/inifiles/dos.ini6
-rw-r--r--tests/inifiles/space.ini9
-rw-r--r--tests/inifiles/uppercase.ini7
11 files changed, 240 insertions, 9 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 142e651..dc9efa1 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -419,6 +419,23 @@ if (WITH_ATGEN)
"${Gammu_SOURCE_DIR}/tests/at-cnmi/${TESTMESSAGE}")
endforeach(TESTMESSAGE $MESSAGES)
+ # AT CREG parsing
+ add_executable(at-creg-reply at-creg-reply.c)
+ target_link_libraries(at-creg-reply libGammu)
+
+ # List test cases
+ file(GLOB MESSAGES
+ RELATIVE "${Gammu_SOURCE_DIR}/tests/at-creg"
+ "${Gammu_SOURCE_DIR}/tests/at-creg/*.dump")
+ list(SORT MESSAGES)
+
+ foreach(TESTMESSAGE ${MESSAGES})
+ string(REPLACE .dump "" TESTNAME ${TESTMESSAGE})
+ add_test("at-creg-reply-${TESTNAME}"
+ "${GAMMU_TEST_PATH}/at-creg-reply${GAMMU_TEST_SUFFIX}"
+ "${Gammu_SOURCE_DIR}/tests/at-creg/${TESTMESSAGE}")
+ endforeach(TESTMESSAGE $MESSAGES)
+
# AT memory parsing
add_executable(at-getmemory-reply at-getmemory-reply.c)
target_link_libraries(at-getmemory-reply libGammu)
@@ -741,20 +758,36 @@ foreach(TESTCONFIG ${CONFIGS})
endforeach(TESTCONFIG $CONFIGS)
+# INI file parsing
+add_executable(inifile inifile.c)
+target_link_libraries(inifile libGammu)
+file(GLOB INIFILES
+ RELATIVE "${Gammu_SOURCE_DIR}/tests/inifiles"
+ "${Gammu_SOURCE_DIR}/tests/inifiles/*.ini")
+list(SORT INIFILES)
+
+foreach(TESTINIFILE ${INIFILES})
+ add_test(inifile-${TESTINIFILE} "${GAMMU_TEST_PATH}/inifile${GAMMU_TEST_SUFFIX}" "${Gammu_SOURCE_DIR}/tests/inifiles/${TESTINIFILE}")
+endforeach(TESTINIFILE $INIFILES)
+
# Examples
+add_executable(phone-info "${Gammu_SOURCE_DIR}/docs/develop/examples/phone-info.c")
+target_link_libraries(phone-info libGammu)
+add_executable(custom-config "${Gammu_SOURCE_DIR}/docs/develop/examples/custom-config.c")
+target_link_libraries(custom-config libGammu)
+add_executable(sms-send "${Gammu_SOURCE_DIR}/docs/develop/examples/sms-send.c")
+target_link_libraries(sms-send libGammu)
+add_executable(sms-read "${Gammu_SOURCE_DIR}/docs/develop/examples/sms-read.c")
+target_link_libraries(sms-read libGammu)
+add_executable(smsd "${Gammu_SOURCE_DIR}/docs/develop/examples/smsd.c")
+target_link_libraries(smsd libGammu gsmsd)
+
+# Examples tests, works with dummy phone
if (WITH_BACKUP)
- add_executable(phone-info "${Gammu_SOURCE_DIR}/docs/develop/examples/phone-info.c")
- target_link_libraries(phone-info libGammu)
add_test(phone-info "${GAMMU_TEST_PATH}/phone-info${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
- add_executable(sms-send "${Gammu_SOURCE_DIR}/docs/develop/examples/sms-send.c")
- target_link_libraries(sms-send libGammu)
+ add_test(custom-config "${GAMMU_TEST_PATH}/custom-config${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammu-dummy" none dummy)
add_test(sms-send "${GAMMU_TEST_PATH}/sms-send${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
- add_executable(sms-read "${Gammu_SOURCE_DIR}/docs/develop/examples/sms-read.c")
- target_link_libraries(sms-read libGammu)
add_test(sms-read "${GAMMU_TEST_PATH}/sms-read${GAMMU_TEST_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/.gammurc")
- add_executable(smsd "${Gammu_SOURCE_DIR}/docs/develop/examples/smsd.c")
- target_link_libraries(smsd libGammu)
- target_link_libraries(smsd gsmsd)
endif (WITH_BACKUP)
diff --git a/tests/at-creg-reply.c b/tests/at-creg-reply.c
new file mode 100644
index 0000000..8b684ed
--- /dev/null
+++ b/tests/at-creg-reply.c
@@ -0,0 +1,103 @@
+/* Test for reading network status on AT driver */
+
+#include <gammu.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
+#include "../libgammu/gsmstate.h" /* Needed for state machine internals */
+#include "../libgammu/gsmphones.h" /* Phone data */
+
+#include "common.h"
+
+#define BUFFER_SIZE 16384
+
+extern GSM_Error ATGEN_ReplyGetNetworkLAC_CID(GSM_Protocol_Message msg, GSM_StateMachine *s);
+
+int main(int argc, char **argv)
+{
+ GSM_Debug_Info *debug_info;
+ GSM_Phone_ATGENData *Priv;
+ GSM_Phone_Data *Data;
+ unsigned char buffer[BUFFER_SIZE];
+ FILE *f;
+ size_t len;
+ GSM_StateMachine *s;
+ GSM_Protocol_Message msg;
+ GSM_Error error;
+ GSM_NetworkInfo NetworkInfo;
+
+ /* Check parameters */
+ if (argc != 2) {
+ printf("Not enough parameters!\nUsage: at-creg-reply comm.dump\n");
+ return 1;
+ }
+
+ /* Open file */
+ f = fopen(argv[1], "r");
+ if (f == NULL) {
+ printf("Could not open %s\n", argv[1]);
+ return 1;
+ }
+
+ /* Read data */
+ len = fread(buffer, 1, sizeof(buffer) - 1, f);
+ if (!feof(f)) {
+ printf("Could not read whole file %s\n", argv[1]);
+ fclose(f);
+ return 1;
+ }
+ /* Zero terminate data */
+ buffer[len] = 0;
+
+ /* Close file */
+ fclose(f);
+
+ /* Configure state machine */
+ debug_info = GSM_GetGlobalDebug();
+ GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
+ GSM_SetDebugLevel("textall", debug_info);
+
+ /* Allocates state machine */
+ s = GSM_AllocStateMachine();
+ test_result(s != NULL);
+ debug_info = GSM_GetDebug(s);
+ GSM_SetDebugGlobal(TRUE, debug_info);
+
+ /* Initialize AT engine */
+ Data = &s->Phone.Data;
+ Data->ModelInfo = GetModelData(NULL, NULL, "unknown", NULL);
+ Data->NetworkInfo = &NetworkInfo;
+ Data->RequestID = ID_GetNetworkInfo;
+ Priv = &s->Phone.Data.Priv.ATGEN;
+ Priv->ReplyState = AT_Reply_OK;
+ Priv->SMSMode = SMS_AT_PDU;
+ Priv->Charset = AT_CHARSET_UCS2;
+
+ /* Init message */
+ msg.Type = 0;
+ msg.Length = len;
+ msg.Buffer = buffer;
+ SplitLines(msg.Buffer, msg.Length, &Priv->Lines, "\x0D\x0A", 2, "\"", 1, TRUE);
+
+ /* Parse it */
+ error = ATGEN_ReplyGetNetworkLAC_CID(msg, s);
+
+ /* This is normally done by ATGEN_Terminate */
+ FreeLines(&Priv->Lines);
+ GetLineString(NULL, NULL, 0);
+
+ /* Free state machine */
+ GSM_FreeStateMachine(s);
+
+ gammu_test_result(error, "ATGEN_ReplyGetCNMIMode");
+
+ printf("Network: %d\nLAC: %s\nCID: %s\n", NetworkInfo.State, NetworkInfo.LAC, NetworkInfo.CID);
+
+ return 0;
+}
+
+/* Editor configuration
+ * vim: noexpandtab sw=8 ts=8 sts=8 tw=72:
+ */
+
diff --git a/tests/at-creg/huawei.dump b/tests/at-creg/huawei.dump
new file mode 100644
index 0000000..8be11ce
--- /dev/null
+++ b/tests/at-creg/huawei.dump
@@ -0,0 +1,3 @@
+AT+CREG?
++CREG: 2,1,4CA,81DE445
+OK
diff --git a/tests/at-creg/none.dump b/tests/at-creg/none.dump
new file mode 100644
index 0000000..93eb58d
--- /dev/null
+++ b/tests/at-creg/none.dump
@@ -0,0 +1,4 @@
+AT+CREG?
++CREG: 0,0
+OK
+
diff --git a/tests/at-creg/siemens.dump b/tests/at-creg/siemens.dump
new file mode 100644
index 0000000..d65be82
--- /dev/null
+++ b/tests/at-creg/siemens.dump
@@ -0,0 +1,3 @@
+AT+CREG?
++CREG: 0,1,"5E25","605F"
+OK
diff --git a/tests/inifile.c b/tests/inifile.c
new file mode 100644
index 0000000..e496acf
--- /dev/null
+++ b/tests/inifile.c
@@ -0,0 +1,46 @@
+/**
+ * INI file parsing tests.
+ */
+
+#include <gammu.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "common.h"
+
+int main(int argc, char **argv)
+{
+ GSM_Error error;
+ INI_Section *ini = NULL;
+ int intval;
+ gboolean boolval;
+ char *strval;
+
+ /* Check parameters */
+ if (argc != 2) {
+ printf("Not enough parameters!\nUsage: initfile ini_file\n");
+ return 1;
+ }
+
+ error = INI_ReadFile(argv[1], FALSE, &ini);
+ gammu_test_result(error, "INI_ReadFile");
+ test_result(ini != NULL);
+
+ intval = INI_GetInt(ini, "section", "intval", -1);
+ test_result(intval == 65536);
+
+ boolval = INI_GetBool(ini, "section", "trueval", FALSE);
+ test_result(boolval == TRUE);
+
+ boolval = INI_GetBool(ini, "section", "falseval", TRUE);
+ test_result(boolval == FALSE);
+
+ strval = INI_GetValue(ini, "section", "val1", FALSE);
+ test_result(strval != NULL);
+ test_result(strcmp(strval, "ABCDE abcde") == 0);
+
+ INI_Free(ini);
+
+ return 0;
+}
+
diff --git a/tests/inifiles/basic.ini b/tests/inifiles/basic.ini
new file mode 100644
index 0000000..e5a21ca
--- /dev/null
+++ b/tests/inifiles/basic.ini
@@ -0,0 +1,6 @@
+[section]
+intval = 65536
+trueval = true
+falseval = false
+val1 = ABCDE abcde
+
diff --git a/tests/inifiles/comments.ini b/tests/inifiles/comments.ini
new file mode 100644
index 0000000..51be736
--- /dev/null
+++ b/tests/inifiles/comments.ini
@@ -0,0 +1,11 @@
+[section]
+;intval = 1
+intval = 65536
+;intval = 1
+trueval = true
+falseval = false
+#val1 = ABCDE
+val1 = ABCDE abcde
+#val1 = ABCDE
+
+
diff --git a/tests/inifiles/dos.ini b/tests/inifiles/dos.ini
new file mode 100644
index 0000000..5ffed11
--- /dev/null
+++ b/tests/inifiles/dos.ini
@@ -0,0 +1,6 @@
+[section]
+intval = 65536
+trueval = true
+falseval = false
+val1 = ABCDE abcde
+
diff --git a/tests/inifiles/space.ini b/tests/inifiles/space.ini
new file mode 100644
index 0000000..a85334c
--- /dev/null
+++ b/tests/inifiles/space.ini
@@ -0,0 +1,9 @@
+[section]
+ intval = 65536
+ trueval = true
+
+falseval = false
+
+val1 = ABCDE abcde
+
+
diff --git a/tests/inifiles/uppercase.ini b/tests/inifiles/uppercase.ini
new file mode 100644
index 0000000..ffe2fc7
--- /dev/null
+++ b/tests/inifiles/uppercase.ini
@@ -0,0 +1,7 @@
+[SECTION]
+INTVAL = 65536
+TRUEVAL = TRUE
+FALSEVAL = FALSE
+VAL1 = ABCDE abcde
+
+