diff options
author | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:00:27 +0900 |
---|---|---|
committer | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:00:27 +0900 |
commit | 2e527b3ece756531f1b40a7bff34884d8bbe35bf (patch) | |
tree | dc94f0c578348defbc836737f26169df2ad62199 /test | |
parent | 30914695de4a9c11b3a4e1a23be815a2d0f2bbdd (diff) | |
download | libslp-alarm-tizen_2.0.tar.gz libslp-alarm-tizen_2.0.tar.bz2 libslp-alarm-tizen_2.0.zip |
Diffstat (limited to 'test')
-rwxr-xr-x | test/CMakeLists.txt | 8 | ||||
-rw-r--r-- | test/test_alarmdb.c | 236 |
2 files changed, 244 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..f5aa089 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) + +ADD_EXECUTABLE(test_alarmdb test_alarmdb.c) +TARGET_LINK_LIBRARIES(test_alarmdb alarm-engine) + +INSTALL(TARGETS test_alarmdb DESTINATION bin) + diff --git a/test/test_alarmdb.c b/test/test_alarmdb.c new file mode 100644 index 0000000..1f44b9c --- /dev/null +++ b/test/test_alarmdb.c @@ -0,0 +1,236 @@ +/* +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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://floralicense.org/license/ +* +* 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 <getopt.h> +#include <time.h> +#include <string.h> + +#include "../include/alarm-engine.h" + +void usage(char *name) +{ + fprintf(stderr, + "Usage: %s [-l] [-L author] [-a add] [-d id] [-s id] [-e id] [-v id]\n", + name); + fprintf(stderr, "\t -l, --datalist list alarm data\n"); + fprintf(stderr, "\t -L, --author author list alarm data\n"); + fprintf(stderr, "\t -a, --add add alarm data\n"); + fprintf(stderr, "\t -d, --del delete alarm data\n"); + fprintf(stderr, "\t -s, --snooze set alarm enable \n"); + fprintf(stderr, "\t -e, --enable set alarm snooze\n"); + fprintf(stderr, "\t -v, --view view alarm data\n"); + exit(EXIT_FAILURE); +} + +void prt_data_list(void) +{ + printf("%s is called\n", __func__); + struct alarm_data_list *adl = NULL; + struct alarm_data_list *t = NULL; + + adl = alarmdb_get_data_list_all(); + if (!adl) { + printf("Empty\n"); + } + t = adl; + while (t) { + printf("[%d] %d| %d| %d| %s| %d| %d| %d| %d|" + "%d| %d| %d| [%d] %d| %d| %d|" + "%d| %s| %d\n", + t->ad.id, t->ad.alarm_mgr_id, t->ad.enable, t->ad.author, + t->ad.name, (int)t->ad.stime, (int)t->ad.etime, + (int)t->ad.sdate, (int)t->ad.edate, t->ad.repeat_once, + t->ad.repeat_every, t->ad.repeat_weekly, + t->ad.snooze_enable, t->ad.snooze_min, + t->ad.snooze_times, t->ad.count, t->ad.type, t->ad.tone, + t->ad.volume); + t = t->next; + } + alarmdb_free_data_list(adl); +} + +void prt_data_list_by_author(char author) +{ + printf("%s is called\n", __func__); + struct alarm_data_list *adl = NULL; + struct alarm_data_list *t = NULL; + + adl = alarmdb_get_data_list_by_author(author); + if (!adl) { + printf("Empty\n"); + } + t = adl; + while (t) { + printf("[%d] %d| %d| %d| %s| %d| %d| %d| %d|" + "%d| %d| %d| [%d] %d| %d| %d|" + "%d| %s| %d\n", + t->ad.id, t->ad.alarm_mgr_id, t->ad.enable, t->ad.author, + t->ad.name, (int)t->ad.stime, (int)t->ad.etime, + (int)t->ad.sdate, (int)t->ad.edate, t->ad.repeat_once, + t->ad.repeat_every, t->ad.repeat_weekly, + t->ad.snooze_enable, t->ad.snooze_min, + t->ad.snooze_times, t->ad.count, t->ad.type, t->ad.tone, + t->ad.volume); + t = t->next; + } + alarmdb_free_data_list(adl); +} + +void prt_data(struct alarm_data *ad) +{ + printf("id: [%d]\n", ad->id); + printf("alarm manager id: [%d]\n", ad->alarm_mgr_id); + printf("enable: [%d]\n", ad->enable); + printf("author: [%d]\n", ad->author); + printf("name: [%s]\n", ad->name); + printf("stime: [%d]\n", (int)ad->stime); + printf("etime: [%d]\n", (int)ad->etime); + printf("sdate: [%d]\n", (int)ad->sdate); + printf("edate: [%d]\n", (int)ad->edate); + printf("repeat_once: [%d]\n", ad->repeat_once); + printf("repeat_every: [%d]\n", ad->repeat_every); + printf("repeat_weekly: [%d]\n", ad->repeat_weekly); + printf("snooze_enable: [%d]\n", ad->snooze_enable); + printf("snooze_min: [%d]\n", ad->snooze_min); + printf("snooze_times: [%d]\n", ad->snooze_times); + printf("count: [%d]\n", ad->count); + printf("type: [%d]\n", ad->type); + printf("tone: [%s]\n", ad->tone); + printf("volume: [%d]\n", ad->volume); +} + +void add_data(time_t tm) +{ + struct alarm_data *ad = NULL; + ad = alarmdb_create_data(); + if (!ad) { + return; + } + + ad->enable = 1; + ad->author = 1; + snprintf(ad->name, sizeof(ad->name), "%s", "New name"); + ad->stime = tm; + ad->etime = tm + 100; + ad->sdate = 0; + ad->edate = 0; + ad->repeat_once = 0; + ad->repeat_every = 1; + ad->repeat_weekly = 0; + ad->snooze_enable = 0; + ad->snooze_min = 5; + ad->snooze_times = 2; + ad->count = 0; + ad->type = 0; + snprintf(ad->tone, sizeof(ad->tone), "%s", "/opt/x1"); + ad->volume = 4; + + alarmdb_add_data(ad); + alarmdb_free_data(ad); +} + +void set_snooze(int id) +{ + alarmdb_set_snooze(id, 1); +} + +void set_enable(int id) +{ + alarmdb_set_enable(id, 1); +} + +void del_data(int id) +{ + alarmdb_del_data(id); +} + +void view_data(int id) +{ + struct alarm_data *ad = NULL; + + ad = alarmdb_create_data(); + if (ad) { + prt_data(ad); + } else { + printf("Not found %d data\n", id); + } + alarmdb_free_data(ad); +} + +int main(int argc, char *argv[]) +{ + int c, r; + // struct alarm_data ad = {0, }; + + r = alarmdb_init(NULL); + if (r < 0) + exit(EXIT_FAILURE); + + while (1) { + int opt_idx = 0; + static struct option long_options[] = { + {"datalist", no_argument, NULL, 'l'}, + {"author", no_argument, NULL, 'L'}, + {"add", no_argument, NULL, 'a'}, + {"delete", no_argument, NULL, 'd'}, + {"enable", no_argument, NULL, 'e'}, + {"snooze", no_argument, NULL, 's'}, + {"view", no_argument, NULL, 'v'}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "lL:a:d:e:s:v:c:", long_options, + &opt_idx); + if (c == -1) + break; + + switch (c) { + case 'l': + prt_data_list(); + break; + case 'L': + prt_data_list_by_author(atoi(optarg)); + break; + case 'a': + add_data(atoi(optarg)); + break; + case 'd': + del_data(atoi(optarg)); + break; + case 'e': + set_enable(atoi(optarg)); + break; + case 's': + set_snooze(atoi(optarg)); + break; + case 'v': + view_data(atoi(optarg)); + break; + default: + usage(argv[0]); + break; + } + } + if (optind < argc) + usage(argv[0]); + + alarmdb_fini(); + + return 0; +} |