summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDanny Jeongseok Seo <S.Seo@samsung.com>2012-08-22 09:04:19 +0900
committerDanny Jeongseok Seo <S.Seo@samsung.com>2012-08-22 09:18:10 +0900
commit606285b0e52ab9a390f3659d3aca940eb4d2094f (patch)
tree81c7291b75da9b00e9dd694041be69aa177b7af3 /test
parent9ef936a92b45b60ba3d9573269c411e34b9f25bf (diff)
downloadconnection-606285b0e52ab9a390f3659d3aca940eb4d2094f.tar.gz
connection-606285b0e52ab9a390f3659d3aca940eb4d2094f.tar.bz2
connection-606285b0e52ab9a390f3659d3aca940eb4d2094f.zip
Diffstat (limited to 'test')
-rw-r--r--test/connection_test.c336
1 files changed, 312 insertions, 24 deletions
diff --git a/test/connection_test.c b/test/connection_test.c
index b161573..46cfe30 100644
--- a/test/connection_test.c
+++ b/test/connection_test.c
@@ -28,7 +28,7 @@
#include <signal.h>
#include "assert.h"
#include "glib.h"
-#include <net_connection.h>
+#include "net_connection.h"
#include <tizen_error.h>
@@ -46,9 +46,9 @@ int test_get_wifi_call_statistics_info(void);
connection_h connection = NULL;
-static void test_state_changed_callback(connection_network_state_e state, void* user_data)
+static void test_state_changed_callback(connection_type_e type, void* user_data)
{
- printf("State changed callback, state : %d\n", state);
+ printf("Type changed callback, connection type : %d\n", type);
}
static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
@@ -63,13 +63,111 @@ static void test_proxy_changed_callback(const char* ipv4_address, const char* ip
ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
}
+static void test_profile_state_callback(connection_profile_h profile, bool is_requested, void* user_data)
+{
+ connection_profile_state_e state;
+ char *profile_name;
+
+ if (connection_profile_get_state(profile, &state) != CONNECTION_ERROR_NONE)
+ return;
+
+ if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
+ return;
+
+ switch (state) {
+ case CONNECTION_PROFILE_STATE_DISCONNECTED:
+ printf("[Disconnected] : %s\n", profile_name);
+ break;
+ case CONNECTION_PROFILE_STATE_ASSOCIATION:
+ printf("[Association] : %s\n", profile_name);
+ break;
+ case CONNECTION_PROFILE_STATE_CONFIGURATION:
+ printf("[Configuration] : %s\n", profile_name);
+ break;
+ case CONNECTION_PROFILE_STATE_CONNECTED:
+ printf("[Connected] : %s\n", profile_name);
+ }
+
+ g_free(profile_name);
+}
+
+static bool test_get_user_selected_profile(connection_profile_h *profile)
+{
+ int rv = 0;
+ int input = 0;
+ char *profile_name;
+ connection_profile_type_e profile_type;
+ connection_profile_state_e profile_state;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+
+ connection_profile_h profile_list[100] = {0,};
+ int profile_count = 0;
+
+ rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator [%d]\n", rv);
+ return false;
+ }
+
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile handle\n");
+ return false;
+ }
+
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return false;
+ }
+
+ if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile type\n");
+ g_free(profile_name);
+ return false;
+ }
+
+ connection_profile_get_state(profile_h, &profile_state);
+
+ if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
+ char *essid;
+ connection_profile_get_wifi_essid(profile_h, &essid);
+ printf("%d. state:%d, profile name:%s, essid:%s\n",
+ profile_count, profile_state, profile_name, (essid)? essid : "");
+ g_free(essid);
+ } else
+ printf("%d. state:%d, profile name : %s\n",
+ profile_count, profile_state, profile_name);
+
+ g_free(profile_name);
+
+ if (profile_count >= 100)
+ break;
+
+ profile_list[profile_count] = profile_h;
+ profile_count++;
+ }
+
+ printf("\nInput profile number : \n");
+ rv = scanf("%d", &input);
+
+ if (input >= profile_count || input < 0) {
+ printf("Wrong number!!\n");
+ return false;
+ }
+
+ *profile = profile_list[input];
+
+ return true;
+}
+
int test_register_client(void)
{
int err = connection_create(&connection);
if (CONNECTION_ERROR_NONE == err) {
- connection_set_network_state_changed_cb(connection, test_state_changed_callback, NULL);
+ connection_set_type_changed_cb(connection, test_state_changed_callback, NULL);
connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
} else {
@@ -102,9 +200,9 @@ int test_deregister_client(void)
int test_get_network_state(void)
{
int rv = 0;
- connection_network_state_e net_state;
+ connection_type_e net_state;
- rv = connection_get_network_state(connection, &net_state);
+ rv = connection_get_type(connection, &net_state);
if (rv != CONNECTION_ERROR_NONE) {
printf("Fail to get network state [%d]\n", rv);
@@ -186,37 +284,203 @@ int test_get_current_ip(void)
int test_get_call_statistics_info(void)
{
- int rv = 0;
+ long long rv = 0;
- connection_get_last_received_data_size(connection, &rv);
- printf("last recv data size [%d]\n", rv);
- connection_get_last_sent_data_size(connection, &rv);
- printf("last sent data size [%d]\n",rv );
- connection_get_total_received_data_size (connection, &rv);
- printf("total received data size [%d]\n",rv );
- connection_get_total_sent_data_size (connection, &rv);
- printf("total sent data size [%d]\n", rv);
+ connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
+ printf("last recv data size [%lld]\n", rv);
+ connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
+ printf("last sent data size [%lld]\n",rv );
+ connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
+ printf("total received data size [%lld]\n",rv );
+ connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
+ printf("total sent data size [%lld]\n", rv);
return 1;
}
int test_get_wifi_call_statistics_info(void)
{
+ long long rv = 0;
+
+ connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
+ printf("WiFi last recv data size [%lld]\n", rv);
+ connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
+ printf("WiFi last sent data size [%lld]\n",rv );
+ connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
+ printf("WiFi total received data size [%lld]\n",rv );
+ connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
+ printf("WiFi total sent data size [%lld]\n", rv);
+
+ return 1;
+}
+
+int test_get_profile_list(void)
+{
+ int rv = 0;
+ char *profile_name;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+
+ rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator [%d]\n", rv);
+ return -1;
+ }
+
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile handle\n");
+ return -1;
+ }
+
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return -1;
+ }
+ printf("profile name : %s\n", profile_name);
+ g_free(profile_name);
+ }
+
+ return 1;
+}
+
+int test_get_connected_profile_list(void)
+{
+ int rv = 0;
+ char *profile_name;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+
+ rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator [%d]\n", rv);
+ return -1;
+ }
+
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile handle\n");
+ return -1;
+ }
+
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return -1;
+ }
+ printf("profile name : %s\n", profile_name);
+ g_free(profile_name);
+ }
+
+ return 1;
+}
+
+int test_get_current_profile(void)
+{
int rv = 0;
+ char *profile_name;
+ connection_profile_h profile_h;
+
+ rv = connection_get_current_profile(connection, &profile_h);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator [%d]\n", rv);
+ return -1;
+ }
+
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return -1;
+ }
+ printf("profile name : %s\n", profile_name);
+ g_free(profile_name);
+
+ connection_profile_destroy(profile_h);
+
+ return 1;
+}
+
+int test_open_profile(void)
+{
+ connection_profile_h profile;
+ if (test_get_user_selected_profile(&profile) == false)
+ return -1;
+
+ if (connection_open_profile(connection, profile) != CONNECTION_ERROR_NONE) {
+ printf("Connection open Failed!!\n");
+ return -1;
+ }
+
+ if (connection_profile_set_state_changed_cb(profile,
+ test_profile_state_callback, NULL) != CONNECTION_ERROR_NONE) {
+ printf("Set profile callback Failed!!\n");
+ return -1;
+ }
+
+ return 1;
+}
+
+int test_open_cellular_service_type(void)
+{
+ int input;
+ int rv;
+ int service_type;
+ connection_profile_h profile;
+ printf("\nInput profile type(1:Internet, 2:MMS, 3:WAP, 4:Prepaid internet, 5:Prepaid MMS : \n");
+ rv = scanf("%d", &input);
+
+ switch (input) {
+ case 1:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
+ break;
+ case 2:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
+ break;
+ case 3:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_WAP;
+ break;
+ case 4:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
+ break;
+ case 5:
+ service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
+ break;
+ default:
+ printf("Wrong number!!\n");
+ return -1;
+ }
- connection_get_wifi_last_received_data_size(connection, &rv);
- printf("WiFi last recv data size [%d]\n", rv);
- connection_get_wifi_last_sent_data_size(connection, &rv);
- printf("WiFi last sent data size [%d]\n",rv );
- connection_get_wifi_total_received_data_size (connection, &rv);
- printf("WiFi total received data size [%d]\n",rv );
- connection_get_wifi_total_sent_data_size (connection, &rv);
- printf("WiFi total sent data size [%d]\n", rv);
+ if (connection_open_cellular_service_type(connection, service_type, &profile) != CONNECTION_ERROR_NONE) {
+ printf("Connection open Failed!!\n");
+ return -1;
+ }
+
+ if (connection_profile_set_state_changed_cb(profile,
+ test_profile_state_callback, NULL) != CONNECTION_ERROR_NONE) {
+ printf("Set profile callback Failed!!\n");
+ connection_profile_destroy(profile);
+ return -1;
+ }
+
+ connection_profile_destroy(profile);
return 1;
}
-int main(int argc, char **argv){
+int test_close_profile(void)
+{
+ connection_profile_h profile;
+ if (test_get_user_selected_profile(&profile) == false)
+ return -1;
+
+ if (connection_close_profile(connection, profile) != CONNECTION_ERROR_NONE) {
+ printf("Connection close Failed!!\n");
+ return -1;
+ }
+
+ return 1;
+}
+
+int main(int argc, char **argv)
+{
GMainLoop *mainloop;
mainloop = g_main_loop_new (NULL, FALSE);
@@ -255,6 +519,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
printf("7 - Get current Ip address\n");
printf("8 - Get cellular data call statistics\n");
printf("9 - Get WiFi data call statistics\n");
+ printf("a - Get Profile list\n");
+ printf("b - Get Connected Profile list\n");
+ printf("c - Get Current profile\n");
+ printf("d - Open connection with profile\n");
+ printf("e - Open cellular service type\n");
+ printf("f - Close connection with profile\n");
printf("0 - Exit \n");
printf("ENTER - Show options menu.......\n");
@@ -288,6 +558,24 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
case '9': {
rv = test_get_wifi_call_statistics_info();
} break;
+ case 'a': {
+ rv = test_get_profile_list();
+ } break;
+ case 'b': {
+ rv = test_get_connected_profile_list();
+ } break;
+ case 'c': {
+ rv = test_get_current_profile();
+ } break;
+ case 'd': {
+ rv = test_open_profile();
+ } break;
+ case 'e': {
+ rv = test_open_cellular_service_type();
+ } break;
+ case 'f': {
+ rv = test_close_profile();
+ } break;
}
return TRUE;
}