summaryrefslogtreecommitdiffstats
path: root/tinySMS/test
diff options
context:
space:
mode:
Diffstat (limited to 'tinySMS/test')
-rw-r--r--tinySMS/test/droid-makefile28
-rw-r--r--tinySMS/test/stdafx.c26
-rw-r--r--tinySMS/test/stdafx.h41
-rw-r--r--tinySMS/test/targetver.h14
-rw-r--r--tinySMS/test/test.c104
-rw-r--r--tinySMS/test/test.vcproj227
-rw-r--r--tinySMS/test/test_packing.h140
-rw-r--r--tinySMS/test/test_rpdu.h272
-rw-r--r--tinySMS/test/test_tpdu.h250
9 files changed, 1102 insertions, 0 deletions
diff --git a/tinySMS/test/droid-makefile b/tinySMS/test/droid-makefile
new file mode 100644
index 0000000..76e5f0c
--- /dev/null
+++ b/tinySMS/test/droid-makefile
@@ -0,0 +1,28 @@
+APP := test
+
+CFLAGS := $(CFLAGS_COMMON) -I../include -I../../tinySAK/src
+LDFLAGS := $(LDFLAGS_COMMON) -Wl,-Bsymbolic,--whole-archive -l$(PROJECT) -ltinySAK -Wl,--entry=main
+
+all: $(APP)
+
+OBJS += $(APP).o
+
+$(APP): $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+ $(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
+
+install: $(APP)
+ $(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(EXEC_DIR)/$(APP)
+ $(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(EXEC_DIR)/$(APP)
+
+run:
+ $(ANDROID_SDK_ROOT)/tools/adb shell $(EXEC_DIR)/$(APP)
+
+#dbg:
+# $(MAKE) $(MAKEFILE) DEBUG="-g -DDEBUG"
+# $(MAKE) $(MAKEFILE) install
+
+clean:
+ @rm -f $(OBJS) $(APP) \ No newline at end of file
diff --git a/tinySMS/test/stdafx.c b/tinySMS/test/stdafx.c
new file mode 100644
index 0000000..59df1b5
--- /dev/null
+++ b/tinySMS/test/stdafx.c
@@ -0,0 +1,26 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/tinySMS/test/stdafx.h b/tinySMS/test/stdafx.h
new file mode 100644
index 0000000..13e27fa
--- /dev/null
+++ b/tinySMS/test/stdafx.h
@@ -0,0 +1,41 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+#ifndef TEST_SMS_STDAFX_H
+#define TEST_SMS_STDAFX_H
+
+#ifdef WIN32
+#include "targetver.h"
+#endif
+
+#include <stdio.h>
+
+#if (defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE)) && !defined(__SYMBIAN32__)
+#include <tchar.h>
+#endif
+
+
+
+// TODO: reference additional headers your program requires here
+#include <string.h>
+
+#endif /* TEST_SMS_STDAFX_H */
diff --git a/tinySMS/test/targetver.h b/tinySMS/test/targetver.h
new file mode 100644
index 0000000..83ed1ac
--- /dev/null
+++ b/tinySMS/test/targetver.h
@@ -0,0 +1,14 @@
+#ifndef SMS_TEST_TARGETVER_H
+#define SMS_TEST_TARGETVER_H
+// The following macros define the minimum required platform. The minimum required platform
+// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
+// your application. The macros work by enabling all features available on platform versions up to and
+// including the version specified.
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
+#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#endif /* SMS_TEST_TARGETVER_H */
diff --git a/tinySMS/test/test.c b/tinySMS/test/test.c
new file mode 100644
index 0000000..4a3932e
--- /dev/null
+++ b/tinySMS/test/test.c
@@ -0,0 +1,104 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+#include "stdafx.h"
+
+#include "tsk.h"
+#include "tinysms.h"
+
+char* tohex(uint8_t* ptr, size_t size)
+{
+ char* ret = tsk_null;
+ size_t i;
+ for(i=0;i<size;i++){
+ tsk_strcat_2(&ret, "%.2X", *ptr++);
+ }
+ return ret;
+}
+
+void printhex(const char* what, uint8_t* ptr, size_t size)
+{
+ size_t i;
+ printf("%s", what);
+ for(i=0;i<size;i++){
+ printf("%.2X", *ptr++);
+ }
+ printf("\n");
+}
+
+tsk_bool_t bin_equals(const uint8_t* b1, const uint8_t* b2, size_t size)
+{
+ size_t i;
+
+ // we assume that sizeof(b1)==sizeof(b2)
+ if(!b1 || !b2 || !size){
+ return tsk_false;
+ }
+ for(i=0; i<size;i++){
+ if(b1[i] != b2[i]){
+ return tsk_false;
+ }
+ }
+ return tsk_true;
+}
+
+
+#include "test_packing.h"
+#include "test_tpdu.h"
+#include "test_rpdu.h"
+
+
+#define RUN_TEST_LOOP 1
+
+#define RUN_TEST_ALL 0
+#define RUN_TEST_PACKING 0
+#define RUN_TEST_TPDU 0
+#define RUN_TEST_RPDU 1
+
+
+#ifdef _WIN32_WCE
+int _tmain(int argc, _TCHAR* argv[])
+#else
+int main()
+#endif
+{
+#if RUN_TEST_LOOP
+ for(;;)
+#endif
+ {
+ /* Print copyright information */
+ printf("Doubango Project\nCopyright (C) 2009 - 2010 Mamadou Diop \n\n");
+
+#if RUN_TEST_ALL || RUN_TEST_PACKING
+ test_packing();
+#endif
+
+#if RUN_TEST_ALL || RUN_TEST_TPDU
+ test_tpdu();
+#endif
+
+#if RUN_TEST_ALL || RUN_TEST_RPDU
+ test_rpdu();
+#endif
+
+ }
+} \ No newline at end of file
diff --git a/tinySMS/test/test.vcproj b/tinySMS/test/test.vcproj
new file mode 100644
index 0000000..22db15b
--- /dev/null
+++ b/tinySMS/test/test.vcproj
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="test"
+ ProjectGUID="{BD24A663-4018-41EC-A250-4A57CDD2F13B}"
+ RootNamespace="test"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\thirdparties\win32\include;..\..\tinySAK\src;..\..\tinySMS\include"
+ PreprocessorDefinitions="DEBUG_LEVEL=DEBUG_LEVEL_INFO;WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)\tinySAK.lib $(OutDir)\tinySMS.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ CompileAs="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\tinySMS\test\stdafx.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tinySMS\test\test.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\..\tinySMS\test\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tinySMS\test\targetver.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Tests"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath="..\..\tinySMS\test\test_packing.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tinySMS\test\test_rpdu.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tinySMS\test\test_tpdu.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/tinySMS/test/test_packing.h b/tinySMS/test/test_packing.h
new file mode 100644
index 0000000..a674ef0
--- /dev/null
+++ b/tinySMS/test/test_packing.h
@@ -0,0 +1,140 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef _TEST_SMSPACKING_H
+#define _TEST_SMSPACKING_H
+
+typedef struct test_message_7bit_s{
+ const char* ascii;
+ const char* _7bit;
+}
+test_message_7bit_t;
+
+test_message_7bit_t test_messages_7bit[] =
+{
+ "a","\x61",
+ "ab","\x61\x31",
+ "abc","\x61\xF1\x18",
+ "abcdefg","\x61\xF1\x98\x5C\x36\x9F\x01",
+ "abcdefgh","\x61\xF1\x98\x5C\x36\x9F\xD1",
+ "abcdefghi","\x61\xF1\x98\x5C\x36\x9F\xD1\x69",
+ "abcdefgh12345678","\x61\xF1\x98\x5C\x36\x9F\xD1\x31\xD9\x8C\x56\xB3\xDD\x70",
+ "abcdefgh123456789","\x61\xF1\x98\x5C\x36\x9F\xD1\x31\xD9\x8C\x56\xB3\xDD\x70\x39",
+ "This is a test sms message","\x54\x74\x7A\x0E\x4A\xCF\x41\x61\x10\xBD\x3C\xA7\x83\xE6\xED\x39\xA8\x5D\x9E\xCF\xC3\xE7\x32",
+ "salut","\xF3\x30\xBB\x4E\x07",
+ "hellohello","\xE8\x32\x9B\xFD\x46\x97\xD9\xEC\x37",
+};
+
+void test_7bit()
+{
+ tsk_size_t i;
+ tsk_buffer_t* buffer;
+ char* temp;
+
+ /* To 7bit */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((buffer = tsms_pack_to_7bit(test_messages_7bit[i].ascii))){
+ /*if((temp = tohex(buffer->data, buffer->size))){
+ if(!tsk_striequals(temp, test_messages_7bit[i]._7bit)){
+ TSK_DEBUG_ERROR("tsms_pack_to_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
+ }
+ TSK_FREE(temp);
+ }*/
+ if(!bin_equals(buffer->data, test_messages_7bit[i]._7bit, buffer->size)){
+ TSK_DEBUG_ERROR("tsms_pack_to_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ }
+
+ /* From 7bit */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((temp = tsms_pack_from_7bit(test_messages_7bit[i]._7bit, (tsk_size_t)tsk_strlen(test_messages_7bit[i]._7bit)))){
+ if(!tsk_striequals(temp, test_messages_7bit[i].ascii)){
+ TSK_DEBUG_ERROR("tsms_pack_from_7bit(\"%s\") Failed.\n", test_messages_7bit[i].ascii);
+ }
+ TSK_FREE(temp);
+ }
+ }
+}
+
+void test_8bit()
+{
+ tsk_size_t i;
+ tsk_buffer_t* buffer;
+ char* temp;
+
+ /* To 8bit */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((buffer = tsms_pack_to_8bit(test_messages_7bit[i].ascii))){
+ if(!tsk_strequals(buffer->data, test_messages_7bit[i].ascii)){
+ TSK_DEBUG_INFO("tsms_pack_to_8bit(%s) Failed", test_messages_7bit[i].ascii);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ }
+
+ /* From 8bit */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((temp = tsms_pack_from_8bit(test_messages_7bit[i].ascii, (tsk_size_t)tsk_strlen(test_messages_7bit[i].ascii)))){
+ if(!tsk_strequals(temp, test_messages_7bit[i].ascii)){
+ TSK_DEBUG_INFO("tsms_pack_from_8bit(%s) Failed", test_messages_7bit[i].ascii);
+ }
+ TSK_FREE(temp);
+ }
+ }
+}
+
+void test_ucs2()
+{
+ tsk_size_t i;
+ tsk_buffer_t* buffer;
+ char* temp;
+
+ /* To ucs2 */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((buffer = tsms_pack_to_ucs2(test_messages_7bit[i].ascii))){
+ if(!tsk_strequals(buffer->data, test_messages_7bit[i].ascii)){
+ TSK_DEBUG_INFO("tsms_pack_to_ucs2(%s) Failed", test_messages_7bit[i].ascii);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ }
+
+ /* From ucs2 */
+ for(i=0; i<sizeof(test_messages_7bit)/sizeof(test_message_7bit_t); i++){
+ if((temp = tsms_pack_from_ucs2(test_messages_7bit[i].ascii, (tsk_size_t)tsk_strlen(test_messages_7bit[i].ascii)))){
+ if(!tsk_strequals(temp, test_messages_7bit[i].ascii)){
+ TSK_DEBUG_INFO("tsms_pack_from_ucs2(%s) Failed", test_messages_7bit[i].ascii);
+ }
+ TSK_FREE(temp);
+ }
+ }
+}
+
+void test_packing()
+{
+ test_ucs2();
+ test_8bit();
+ test_7bit();
+}
+
+#endif /* _TEST_SMSPACKING_H */
diff --git a/tinySMS/test/test_rpdu.h b/tinySMS/test/test_rpdu.h
new file mode 100644
index 0000000..38d37b0
--- /dev/null
+++ b/tinySMS/test/test_rpdu.h
@@ -0,0 +1,272 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef _TEST_SMSRPDU_H
+#define _TEST_SMSRPDU_H
+
+void test_i_rpdata(const void* data, tsk_size_t size, tsk_bool_t MobOrig)
+{
+ tsms_rpdu_message_t* rp_message = tsk_null;
+ tsms_tpdu_message_t* tpdu = tsk_null;
+
+ if(!(rp_message = tsms_rpdu_message_deserialize(data, size))){
+ TSK_DEBUG_ERROR("Failed to deserialize the RP-MESSAGE");
+ goto bail;
+ }
+
+ switch(rp_message->mti){
+ case tsms_rpdu_type_data_mo:
+ case tsms_rpdu_type_data_mt:
+ {
+ char* ascii = tsk_null;
+ tsms_rpdu_data_t* rp_data = TSMS_RPDU_DATA(rp_message);
+ if((tpdu = tsms_tpdu_message_deserialize(rp_data->udata->data, rp_data->udata->size, MobOrig))){
+ if(tpdu->mti == tsms_tpdu_mti_deliver_mt || tpdu->mti == tsms_tpdu_mti_submit_mo){ /* SMS-SUBMIT or SMS-DELIVER? */
+ if((ascii = tsms_tpdu_message_get_payload(tpdu))){
+ TSK_DEBUG_INFO("ASCII message=%s", ascii);
+ TSK_FREE(ascii);
+ }
+ }
+ }
+ break;
+ }
+ case tsms_rpdu_type_ack_mo:
+ case tsms_rpdu_type_ack_mt:
+ {
+ tsms_rpdu_ack_t* rp_ack = TSMS_RPDU_ACK(rp_message);
+ // ...do whatever you want
+ if(rp_ack->udata && (tpdu = tsms_tpdu_message_deserialize(rp_ack->udata->data, rp_ack->udata->size, MobOrig))){
+ // ...do whatever you want
+ }
+ TSK_DEBUG_INFO("RP-ACK");
+ break;
+ }
+ case tsms_rpdu_type_error_mo:
+ case tsms_rpdu_type_error_mt:
+ {
+ tsms_rpdu_error_t* rp_error = TSMS_RPDU_ERROR(rp_message);
+ // ...do whatever you want
+ if(rp_error->udata && (tpdu = tsms_tpdu_message_deserialize(rp_error->udata->data, rp_error->udata->size, MobOrig))){
+ // ...do whatever you want
+ }
+ TSK_DEBUG_INFO("RP-ERROR");
+ break;
+ }
+ case tsms_rpdu_type_smma_mo:
+ {
+ tsms_rpdu_smma_t* rp_smma = TSMS_RPDU_SMMA(rp_message);
+ // ...do whatever you want
+ TSK_DEBUG_INFO("RP-SMMA");
+ break;
+ }
+ default:
+ {
+ TSK_DEBUG_INFO("Unknown RP-Message type (%u).", rp_message->mti);
+ break;
+ }
+ }
+
+bail:
+ TSK_OBJECT_SAFE_FREE(rp_message);
+ TSK_OBJECT_SAFE_FREE(tpdu);
+}
+
+void test_o_rpdata_submit()
+{
+ //== Sending RP-DATA(SMS-SUBMIT) ==
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_submit_t* sms_submit = tsk_null;
+ tsms_rpdu_data_t* rp_data = tsk_null;
+ const char* smsc = "+331000009";
+ const char* destination = "+333361234567";
+ const char* short_message = "hello world";
+ uint8_t mr = 0xF5;
+ uint8_t message_number = 0xF8;
+ char* hex;
+
+ // create SMS-SUBMIT message
+ sms_submit = tsms_tpdu_submit_create(mr, smsc, destination);
+ // Set content for SMS-SUBMIT
+ if((buffer = tsms_pack_to_7bit(short_message))){
+ ret = tsms_tpdu_submit_set_userdata(sms_submit, buffer, tsms_alpha_7bit);
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ // create RP-DATA message and print its content (for test only)
+ rp_data = tsms_rpdu_data_create_mo(mr, smsc, TSMS_TPDU_MESSAGE(sms_submit));
+ if((hex = tsms_rpdu_message_tohexastring(TSMS_RPDU_MESSAGE(rp_data)))){
+ TSK_DEBUG_INFO("RP-DATA=%s", hex);
+ TSK_FREE(hex);
+ }
+
+
+ // serialize
+ buffer = tsk_buffer_create_null();
+ ret = tsms_rpdu_data_serialize(rp_data, buffer);
+ // send(socket, buffer->data, buffer->size);
+ // print result (hex) to the console
+ printhex("==RP-DATA(SMS-SUBMIT):", buffer->data, buffer->size);
+
+ // receiving
+ test_i_rpdata(buffer->data, buffer->size, tsk_true);
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_submit);
+ TSK_OBJECT_SAFE_FREE(rp_data);
+}
+
+void test_o_rpdata_deliver()
+{
+ //== Sending RP-DATA(SMS-DELIVER) ==
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_deliver_t* sms_deliver = tsk_null;
+ tsms_rpdu_data_t* rp_data = tsk_null;
+ const char* smsc = "+331000000";
+ const char* originator = "+3361234567";
+ const char* content = "hello world!";
+
+ // create SMS-DELIVER message
+ sms_deliver = tsms_tpdu_deliver_create(smsc, originator);
+ // Set content for SMS-DELIVER
+ if((buffer = tsms_pack_to_7bit(content))){
+ ret = tsms_tpdu_deliver_set_userdata(sms_deliver, buffer, tsms_alpha_7bit);
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+ // create RP-DATA message
+ rp_data = tsms_rpdu_data_create_mt(0x01, smsc, TSMS_TPDU_MESSAGE(sms_deliver));
+ // serialize
+ buffer = tsk_buffer_create_null();
+ ret = tsms_rpdu_data_serialize(rp_data, buffer);
+ // send(socket, buffer->data, buffer->size);
+ // print result (hex) to the console
+ printhex("==RP-DATA(SMS-DELIVER):", buffer->data, buffer->size);
+
+ // receiving
+ test_i_rpdata(buffer->data, buffer->size, tsk_false);
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_deliver);
+ TSK_OBJECT_SAFE_FREE(rp_data);
+}
+
+void test_o_rpdata_smma()
+{
+ //== Sending RP-SMMA ==
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_rpdu_smma_t* rp_smma = tsk_null;
+ uint8_t mr = 0xF5;
+
+ // create RP-SMMA message
+ rp_smma = tsms_rpdu_smma_create(mr);
+ // serialize
+ buffer = tsk_buffer_create_null();
+ ret = tsms_rpdu_data_serialize(rp_smma, buffer);
+ // send(socket, buffer->data, buffer->size);
+ // print result (hex) to the console
+ printhex("==RP-SMMA:", buffer->data, buffer->size);
+
+ // receiving
+ test_i_rpdata(buffer->data, buffer->size, tsk_true);
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(rp_smma);
+}
+
+void test_o_rpdata_ack()
+{
+ //== Sending RP-ACK(SMS-DELIVER-REPORT) ==
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_report_t* sms_report = tsk_null;
+ tsms_rpdu_ack_t* rp_ack= tsk_null;
+ const char* smsc = "+331000000";
+ tsk_bool_t isSUBMIT = tsk_false; /* isDELIVER */
+ tsk_bool_t isERROR = tsk_false;
+ uint8_t mr = 0xF5;
+
+ // create SMS-DELIVER-REPORT message
+ sms_report = tsms_tpdu_report_create(smsc, isSUBMIT, isERROR);
+ // create RP-ACK message (From MS to SC)
+ rp_ack = tsms_rpdu_ack_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report));
+ // serialize
+ buffer = tsk_buffer_create_null();
+ if(!(ret = tsms_rpdu_data_serialize(rp_ack, buffer))){
+ // send(socket, buffer->data, buffer->size);
+ // print result (hex) to the console
+ printhex("==RP-ACK(SMS-DELIVER-REPORT):", buffer->data, buffer->size);
+ }
+
+ // receiving
+ test_i_rpdata(buffer->data, buffer->size, tsk_true);
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_report);
+ TSK_OBJECT_SAFE_FREE(rp_ack);
+}
+
+void test_o_rpdata_error()
+{
+ //== Sending RP-ERROR(SMS-DELIVER-REPORT) ==
+ int ret;
+ tsk_buffer_t* buffer = tsk_null;
+ tsms_tpdu_report_t* sms_report = tsk_null;
+ tsms_rpdu_error_t* rp_error= tsk_null;
+ tsk_bool_t isSUBMIT = tsk_false; /* isDELIVER */
+ tsk_bool_t isERROR = tsk_true;
+ const char* smsc = "+331000000";
+ uint8_t mr = 0xF5;
+
+ // create SMS-DELIVER-REPORT message
+ sms_report = tsms_tpdu_report_create(smsc, isSUBMIT, isERROR);
+ // create RP-ERROR message
+ rp_error = tsms_rpdu_error_create_mo(mr, TSMS_TPDU_MESSAGE(sms_report), 0x0A/*call barred*/);
+ // serialize
+ buffer = tsk_buffer_create_null();
+ if(!(ret = tsms_rpdu_data_serialize(rp_error, buffer))){
+ // send(socket, buffer->data, buffer->size);
+ // print result (hex) to the console
+ printhex("==RP-ERROR(SMS-DELIVER-REPORT):", buffer->data, buffer->size);
+ }
+
+ // receiving
+ test_i_rpdata(buffer->data, buffer->size, tsk_true);
+
+ TSK_OBJECT_SAFE_FREE(buffer);
+ TSK_OBJECT_SAFE_FREE(sms_report);
+ TSK_OBJECT_SAFE_FREE(rp_error);
+}
+
+
+void test_rpdu()
+{
+ test_o_rpdata_submit();
+ //test_o_rpdata_deliver();
+ //test_o_rpdata_smma();
+ //test_o_rpdata_ack();
+ //test_o_rpdata_error();
+
+ //const char* data = "\x03\x01\x41\x09\x01\x00\x01\x80\x01\x32\x42\x00\x69";
+ //test_i_rpdata(data, 13, tsk_false);
+}
+
+#endif /* _TEST_SMSRPDU_H */
diff --git a/tinySMS/test/test_tpdu.h b/tinySMS/test/test_tpdu.h
new file mode 100644
index 0000000..a14f959
--- /dev/null
+++ b/tinySMS/test/test_tpdu.h
@@ -0,0 +1,250 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+#ifndef _TEST_SMSTPDU_H
+#define _TEST_SMSTPDU_H
+
+#define USER_DATA "hellohello"
+
+static uint8_t __pdu_last_mr = 0;
+
+void test_submit()
+{
+ int ret;
+ tsms_tpdu_submit_t* submit = tsk_null;
+ tsk_buffer_t* buffer = tsk_null;
+ char* hex;
+ const char* smsc = "+331000009";
+ const char* destination = "+333361234567";
+ const char* short_message = "hello world";
+ uint8_t mr = 0xF5;
+
+ submit = tsms_tpdu_submit_create(mr, smsc, destination);
+
+ /* encode the user data to GSM 7-bit alphabet */
+ if((buffer = tsms_pack_to_7bit(short_message))){
+ ret = tsms_tpdu_submit_set_userdata(submit, buffer, tsms_alpha_7bit);
+ if((hex = tsms_tpdu_submit_tohexastring(submit))){
+ TSK_DEBUG_INFO("SMS-SUBMIT=%s", hex);
+ TSK_FREE(hex);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+
+ /* receiving */
+ buffer = tsk_buffer_create_null();
+ ret = tsms_tpdu_submit_serialize(submit, buffer);
+ // send(socket, buffer->data, buffer->size);
+
+ TSK_OBJECT_SAFE_FREE(submit);
+ submit = (tsms_tpdu_submit_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
+ if((hex = tsms_tpdu_submit_tohexastring(submit))){
+ TSK_DEBUG_INFO("SMS-SUBMIT=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ TSK_OBJECT_SAFE_FREE(submit);
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+ printf("==========\n");
+}
+
+void test_deliver()
+{
+ int ret;
+ tsms_tpdu_deliver_t* deliver = tsk_null;
+ tsk_buffer_t* buffer = tsk_null;
+ char* hex;
+
+ deliver = tsms_tpdu_deliver_create("+27381000015", "+46708251358");
+
+ /* sending */
+ if((buffer = tsms_pack_to_7bit(USER_DATA))){
+ ret = tsms_tpdu_deliver_set_userdata(deliver, buffer, tsms_alpha_7bit);
+ if((hex = tsms_tpdu_deliver_tohexastring(deliver))){
+ TSK_DEBUG_INFO("SMS-DELIVER=%s", hex);
+ TSK_FREE(hex);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+
+ /* receiving */
+ buffer = tsk_buffer_create_null();
+ tsms_tpdu_deliver_serialize(deliver, buffer);
+
+ TSK_OBJECT_SAFE_FREE(deliver);
+
+ //{
+ // tsms_tpdu_message_t* sms_any = tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
+ // if(sms_any && sms_any->mti == tsms_tpdu_mti_deliver_mt){
+ // //tsms_tpdu_deliver_t* sms_deliver = TSMS_TPDU_DELIVER(sms_any); ==> Yes we can !
+ // char* ascii;
+ // if((ascii = tsms_tpdu_message_get_payload(sms_any))){
+ // TSK_DEBUG_INFO("Message=%s", ascii);
+ // TSK_FREE(ascii);
+ // }
+ // }
+ // TSK_OBJECT_SAFE_FREE(sms_any);
+ //}
+
+ deliver = (tsms_tpdu_deliver_t*)tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
+ if((hex = tsms_tpdu_deliver_tohexastring(deliver))){
+ TSK_DEBUG_INFO("SMS-DELIVER=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ TSK_OBJECT_SAFE_FREE(deliver);
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+ printf("==========\n");
+}
+
+
+void test_report()
+{
+ int ret;
+ tsms_tpdu_report_t* report = tsk_null;
+ tsk_buffer_t* buffer = tsk_null;
+ char* hex;
+ const char* smsc = "+331000009";
+ tsk_bool_t isSUBMIT = tsk_false;
+ tsk_bool_t isERROR = tsk_false;
+
+ report = tsms_tpdu_report_create(smsc, isSUBMIT, isERROR);
+
+ /* sending */
+ if((buffer = tsms_pack_to_7bit(USER_DATA))){
+ ret = tsms_tpdu_deliver_set_userdata(report, buffer, tsms_alpha_7bit);
+ if((hex = tsms_tpdu_deliver_tohexastring(report))){
+ TSK_DEBUG_INFO("SMS-DELIVER-REPORT for RP-ERROR=%s", hex);
+ TSK_FREE(hex);
+ }
+ TSK_OBJECT_SAFE_FREE(buffer);
+ }
+
+ /* receiving */
+ buffer = tsk_buffer_create_null();
+ tsms_tpdu_report_serialize(report, buffer);
+
+ TSK_OBJECT_SAFE_FREE(report);
+ report = (tsms_tpdu_report_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
+ if((hex = tsms_tpdu_report_tohexastring(report))){
+ TSK_DEBUG_INFO("SMS-DELIVER-REPORT for RP-ERROR=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ TSK_OBJECT_SAFE_FREE(report);
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+ printf("==========\n");
+}
+
+void test_command()
+{
+ tsms_tpdu_command_t* command = tsk_null;
+ char* hex;
+ tsk_buffer_t* buffer = tsk_null;
+ const char* smsc = "+331000009";
+ const char* destination = "+333361234567";
+ uint8_t mr = 0xF5;
+ uint8_t message_number = 0xF8;
+
+ command = tsms_tpdu_command_create(mr, smsc, destination, message_number, tsms_tpdu_cmd_delete);
+
+ /*sending*/
+ if((hex = tsms_tpdu_command_tohexastring(command))){
+ TSK_DEBUG_INFO("SMS-COMMAND=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ /* receiving */
+ buffer = tsk_buffer_create_null();
+ tsms_tpdu_command_serialize(command, buffer);
+
+ TSK_OBJECT_SAFE_FREE(command);
+ command = (tsms_tpdu_command_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
+ if((hex = tsms_tpdu_command_tohexastring(command))){
+ TSK_DEBUG_INFO("SMS-COMMAND=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ TSK_OBJECT_SAFE_FREE(command);
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+ printf("==========\n");
+}
+
+void test_sreport()
+{
+ tsms_tpdu_status_report_t* sreport = tsk_null;
+ char* hex;
+ tsk_buffer_t* buffer = tsk_null;
+
+ sreport = tsms_tpdu_status_report_create(__pdu_last_mr++, "+3310000", "+332666", tsms_tpdu_status_busy, tsk_true);
+
+ if((hex = tsms_tpdu_report_tohexastring(sreport))){
+ TSK_DEBUG_INFO("SMS-STATUS-REPORT=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ /* receiving */
+ buffer = tsk_buffer_create_null();
+ tsms_tpdu_status_report_serialize(sreport, buffer);
+
+
+//tsms_tpdu_message_t* sms_any = tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
+//if(sms_any && sms_any->mti == tsms_tpdu_mti_status_report_mt){
+// tsms_tpdu_status_report_t* sms_status_report = TSMS_TPDU_STATUS_REPORT(sms_any);
+// switch(sms_status_report->st){
+// case tsms_tpdu_status_received:
+// case tsms_tpdu_status_forwarded:
+// case tsms_tpdu_status_replaced:
+// // ...
+// default:
+// break;
+// }
+//}
+//TSK_OBJECT_SAFE_FREE(sms_any);
+
+
+ TSK_OBJECT_SAFE_FREE(sreport);
+ sreport = (tsms_tpdu_status_report_t*)tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
+ if((hex = tsms_tpdu_status_report_tohexastring(sreport))){
+ TSK_DEBUG_INFO("SMS-STATUS-REPORT=%s", hex);
+ TSK_FREE(hex);
+ }
+
+ TSK_OBJECT_SAFE_FREE(sreport);
+ TSK_OBJECT_SAFE_FREE(buffer);
+
+ printf("==========\n");
+}
+
+void test_tpdu()
+{
+ test_submit();
+ test_deliver();
+ test_report();
+ test_command();
+ test_sreport();
+}
+
+#endif /* _TEST_SMSTPDU_H */
OpenPOWER on IntegriCloud