summaryrefslogtreecommitdiff
path: root/test/location_appman_test.c
blob: 8de558331f184c84ccb533158e3a10b4f9be2ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
 * liblocation-appman
 *
 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
 *          Genie Kim <daejins.kim@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "location-appman.h"
#include "location-appman-crypt.h"

static GMainLoop *g_mainloop = NULL;

int location_appman_insert_test(void)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;
	int i;

	printf("location_appman_insert_test.\n");

	location_appman_s	test_data[5] = {{"test1_package", "test1_name", "test1_icon", 1, 1325882464, 1325893464, TRUE},
						{"test2_package", "test2_name", "test2_icon", 2, 1325893464, 1325900001, TRUE},
						{"test3_package", "test3_name", "test3_icon", 3, 1325898464, 1325900264, FALSE},
						{"test4_package", "test4_name", "test4_icon", 4, 1325866464, 1325901464, FALSE},
						{"test5_package", "test5_name", "test5_icon", 5, 1325888464, 1325900114, TRUE}};


	for(i = 0; i < 5; i++) {
		rc = location_appman_insert(&test_data[i]);
		if(LOCATION_APPMAN_ERROR_NONE != rc) {
			printf( "Fail to location_app_insert. Error[%d], i = %d\n", rc, i );
			return rc;
		}
	}
	return rc;
}

int location_appman_update_test(void)
{
	location_appman_s	test_update;
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf("location_appman_update_test.\n");

	strcpy(test_update.package, "test2_package");
	strcpy(test_update.appname, "modi2_name");
	strcpy(test_update.appicon, "modi2_icon");
	test_update.appid = 4;
	test_update.installed_date = 1325903464;
	test_update.recently_used = 1325903464;
	test_update.enable = FALSE;

	rc = location_appman_update(&test_update);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_update. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_delete_test()
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf("location_appman_delete_test.\n");

	rc = location_appman_delete((const char*)"test2_package");
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_delete. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_reset_test()
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf("location_appman_reset_test.\n");

	rc = location_appman_reset();
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_delete. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_apps_test_by_installed_date()
{
	location_appman_s *appmantest = NULL;
	int rc = LOCATION_APPMAN_ERROR_NONE, i;
	int list_count = 0;

	rc = location_appman_get_app_list(LOCATION_APPMAN_COLUMN_INSTALLED_DATE, &list_count, &appmantest);

	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "location_appman_get_apps_test. Error[%d]\n", rc);
		return rc;
	}

	for(i = 0; i < list_count; i++) {
		printf( "%s, %s, %s, %d, installed_date = %d, %d, %d\n", appmantest[i].package,
									appmantest[i].appname,
									appmantest[i].appicon,
									appmantest[i].appid,
									appmantest[i].installed_date,
									appmantest[i].recently_used,
									appmantest[i].enable);
	}

	for(i = 0; i < list_count; i++) {
		g_slice_free(location_appman_s, (appmantest + i));
	}

	return rc;
}

int location_appman_get_apps_test_by_recently_used()
{
	location_appman_s *appmantest = NULL;
	int rc = LOCATION_APPMAN_ERROR_NONE, i;
	int list_count = 0;

	rc = location_appman_get_app_list(LOCATION_APPMAN_COLUMN_RECENTLY_USED, &list_count, &appmantest);

	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "location_appman_get_apps_test. Error[%d]\n", rc);
		return rc;
	}

	for(i = 0; i < list_count; i++) {
		printf( "%s, %s, %s, %d, %d, recently_used = %d, %d\n", appmantest[i].package,
												appmantest[i].appname,
												appmantest[i].appicon,
												appmantest[i].appid,
												appmantest[i].installed_date,
												appmantest[i].recently_used,
												appmantest[i].enable);
	}

	for(i = 0; i < list_count; i++) {
		g_slice_free(location_appman_s, (appmantest + i));
	}

	return rc;
}

int location_appman_get_apps_test_by_default()
{
	location_appman_s *appmantest = NULL;
	int rc = LOCATION_APPMAN_ERROR_NONE, i;
	int list_count = 0;

	rc = location_appman_get_app_list(-1, &list_count, &appmantest);

	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "location_appman_get_apps_test. Error[%d]\n", rc);
		return rc;
	}

	for(i = 0; i < list_count; i++) {
		printf( "%s, %s, %s, %d, installed_date = %d, %d, %d\n", appmantest[i].package,
												appmantest[i].appname,
												appmantest[i].appicon,
												appmantest[i].appid,
												appmantest[i].installed_date,
												appmantest[i].recently_used,
												appmantest[i].enable);
	}

	for(i = 0; i < list_count; i++) {
		g_slice_free(location_appman_s, (appmantest + i));
	}

	return rc;
}

/********** GET **********/
int location_appman_get_apps_test()
{
	int rc = LOCATION_APPMAN_ERROR_NONE;
	int	total = 0;

	printf( "location_appman_get_apps_test\n");

	rc = location_appman_get_total_count(&total);
	printf( "return value = %d\n", rc);

	printf( "============== SORTING INSTALLED_DATE ==============\n");
	rc = location_appman_get_apps_test_by_installed_date();
	printf( "location_appman_get_apps_test_by_installed_date : return value = %d\n", rc);

	printf( "============== SORTING RECENTLY_USED ==============\n");
	rc = location_appman_get_apps_test_by_recently_used();
	printf( "location_appman_get_apps_test_by_recently_used : return value = %d\n", rc);

	printf( "============== SORTING DEFAULT ==============\n");
	rc = location_appman_get_apps_test_by_default();
	printf( "location_appman_get_apps_test_by_default : return value = %d\n", rc);

	return rc;
}

int location_appman_get_name_test(const char *package, char **name)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_name_test\n");
	rc = location_appman_get_name(package, name);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_name_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_icon_test(const char *package, char **icon)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_icon_test\n");
	rc = location_appman_get_icon(package, icon);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_icon_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_appid_test(const char *package, int *appid)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_appid_test\n");
	rc = location_appman_get_appid(package, appid);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_appid_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_installed_date_test(const char *package, unsigned int *installed_date)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_installed_date_test\n");
	rc = location_appman_get_installed_date(package, installed_date);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_installed_date_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_recently_used_test(const char *package, unsigned int *recently_used)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_recently_used_test\n");
	rc = location_appman_get_recently_used(package, recently_used);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_recently_used_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_is_enabled_test(const char *package, int *enable)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_get_enable_test\n");
	rc = location_appman_is_enabled(package, enable);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_get_enable_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

/********** SET **********/
int location_appman_set_icon_test(const char *package, char *icon)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_set_icon_test\n");
	rc = location_appman_set_icon(package, icon);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_icon_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_set_appid_test(const char *package, int appid)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_set_appid_test\n");
	rc = location_appman_set_appid(package, appid);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_appid_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_set_installed_date_test(const char *package, unsigned int installed_date)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_set_installed_date_test\n");
	rc = location_appman_set_installed_date(package, installed_date);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_installed_date_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_set_recently_used_test(const char *package, unsigned int recently_used)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_set_recently_used_test\n");
	rc = location_appman_set_recently_used(package, recently_used);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_recently_used_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_set_on_test(const char *package, int onoff)
{
	int rc = LOCATION_APPMAN_ERROR_NONE;

	printf( "location_appman_set_enable_test\n");
	rc = location_appman_set_on(package, onoff);
	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_enable_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_set_get_encrypt_test()
{
	int rc = LOCATION_APPMAN_ERROR_NONE;
	//int nbuf = 0;
	unsigned int n2buf = 0;
	unsigned int nRet = 0;
	char *buf = {0, };
	char tmpstr[32] = "efff222";
	char output[32] = {0, };
	char realvalue[32] = {0, };
	char pack[64] = "test3_package";
	char key[32] = "LocationAppman";


	// name
	printf( "location_appman_set_get_encrypt_test\n");
	rc = location_appman_get_name(pack, &buf);
	printf( "location_appman_set_get_encrypt_test : rc = %d, name = %s\n", rc, buf);

	rc = location_appman_encrypt(NULL, (const char *)buf, output);
	printf( "location_appman_set_get_encrypt_test : rc = %d, name's output = %s\n", rc, output);
	rc = location_appman_decrypt(NULL, (const char *)output, realvalue);
	printf( "location_appman_set_get_encrypt_test : rc = %d, name's realvalue = %s\n", rc, realvalue);
	g_free(buf);

	//recently_used
	rc = location_appman_get_recently_used_test(pack, &n2buf);
	printf( "location_appman_set_get_encrypt_test recently_used = %d\n", n2buf);

	sprintf(buf, "%d", n2buf);
	strcpy(tmpstr, buf);
	rc = location_appman_encrypt(key, (const char*)tmpstr, output);
	printf( "location_appman_set_get_encrypt_test recently_used = %s\n", output);

	rc = location_appman_decrypt(key, (const char*)output, realvalue);
	nRet = (unsigned int)atof(realvalue);
	printf( "location_appman_set_get_encrypt_test : rc = %d, recently's nRet = %d\n", rc, nRet);

	//location_appman_decrypt(pack, output);

	if(LOCATION_APPMAN_ERROR_NONE != rc) {
		printf( "Fail to location_appman_set_encrypt_test. Error[%d]\n", rc);
		return rc;
	}
	return rc;
}

int location_appman_get_set_test()
{
	int rc = LOCATION_APPMAN_ERROR_NONE;
	int nbuf = 0;
	unsigned int n2buf = 0;
	char *buf = {0, };
	char *pack = "test3_package";

	printf( "\n\nDB SET/GET ================ location_app_get_set_test\n");

	rc = location_appman_set_icon(pack, (char *)"set_icon");
	rc = location_appman_set_appid(pack, 12);
	rc = location_appman_set_installed_date(pack, 12000);
	rc = location_appman_set_recently_used(pack, 21000);
	rc = location_appman_set_on(pack, TRUE);

	rc = location_appman_get_name(pack, &buf);
	printf( "get name = %s\n", buf);
	g_free(buf);

	rc = location_appman_get_icon(pack, &buf);
	printf( "get icon = %s\n", buf);
	g_free(buf);

	rc = location_appman_get_appid(pack, &nbuf);
	printf( "get appid = %d\n", nbuf);

	rc = location_appman_get_installed_date(pack, &n2buf);
	printf( "get installed_date = %d\n", n2buf);

	rc = location_appman_get_recently_used(pack, &n2buf);
	printf( "get recently_used = %d\n", n2buf);

	rc = location_appman_is_enabled(pack, &nbuf);
	printf( "get enable = %d\n", nbuf);

	return rc;
}

int location_appman_parse_test()
{
	location_appman_s *appmantest = NULL;
	int rc = LOCATION_APPMAN_ERROR_NONE;
	int findpackage = 0;
	int n;

	const char *xmlbuffer = "<Location>\n<Package>package1</Package>\n<Appid>1</Appid>\n<Enable>1</Enable>\n</Location>";

	rc = location_appamn_parse_manifest(xmlbuffer, &appmantest);

	if (rc == LOCATION_APPMAN_ERROR_NONE) {
		location_appman_register_package(appmantest);
	}

	printf( "%s, %s, %s, %d, installed_date = %d, %d, %d\n", appmantest->package,
									appmantest->appname,
									appmantest->appicon,
									appmantest->appid,
									appmantest->installed_date,
									appmantest->recently_used,
									appmantest->enable);

	//location_appman_s *appman_by_pid = NULL;
	//pid_t t = 0;
	//t = getpid();
	//printf("pid : %d\n", t);
	//n = location_appman_get_package_by_pid(t, &appman_by_pid);

	n = location_appman_find_package("pppp", &findpackage);
	printf("location_appman_find_package : n = %d, findpackage = %d\n", n, findpackage);

	g_slice_free(location_appman_s, appmantest);

	return rc;
}

void location_appman_test()
{
	int n;

	n = location_appman_reset_test();
	printf("location_appman_reset_test : %d\n", n);

	n = location_appman_insert_test();
	printf("location_appman_insert_test : %d\n", n);

	n = location_appman_update_test();
	printf("location_appman_test_update_table_all : %d\n", n);

	n = location_appman_delete_test();
	printf("location_appman_delete_test : %d\n", n);

	n = location_appman_get_apps_test();
	printf("location_appman_test_update_table_all : %d\n", n);

	n = location_appman_get_set_test();
	printf("location_appman_get_set_test : %d\n", n);

	n = location_appman_parse_test();
	printf("location_appman_xml_parser_test : %d\n", n);

	/*
	n = location_appman_set_get_encrypt_test();
	printf("location_appman_get_set_test : %d\n", n);
	*/
}

static gboolean exit_program(gpointer data)
{
	g_main_loop_quit(g_mainloop);
	printf("Quit g_main_loop\n");
	return FALSE;
}

int main(int argc, char **argv)
{
	g_setenv("PKG_NAME", "com.samsung.location-appman-test", 1);
	g_mainloop = g_main_loop_new(NULL, 0);
	location_appman_test();
	g_timeout_add_seconds(30, exit_program, NULL);
	g_main_loop_run(g_mainloop);
	return 0;
}