LCOV - code coverage report
Current view: top level - tests - test_repo_io.c (source / functions) Hit Total Coverage
Test: deployctl-0.3.15.2.96a2d Code Coverage Lines: 47 47 100.0 %
Date: 2018-06-22 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  test_repo.c
       3             :  Created by Danny Goossen, Gioxa Ltd on 12/6/17.
       4             : 
       5             :  MIT License
       6             : 
       7             :  Copyright (c) 2017 deployctl, Gioxa Ltd.
       8             : 
       9             :  Permission is hereby granted, free of charge, to any person obtaining a copy
      10             :  of this software and associated documentation files (the "Software"), to deal
      11             :  in the Software without restriction, including without limitation the rights
      12             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      13             :  copies of the Software, and to permit persons to whom the Software is
      14             :  furnished to do so, subject to the following conditions:
      15             : 
      16             :  The above copyright notice and this permission notice shall be included in all
      17             :  copies or substantial portions of the Software.
      18             : 
      19             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      20             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      22             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      24             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      25             :  SOFTWARE.
      26             : 
      27             :  */
      28             : 
      29             : #include <check.h>
      30             : 
      31             : #include "../src/deployd.h"
      32             : #include "utils.h"
      33             : 
      34             : //TODO update
      35             : 
      36             : //cJSON * JSON_dir_list_x( const char *path,const char *subpath,int recursive, const char * extension);
      37             : 
      38           1 : START_TEST(check_JSON_dir_list_x)
      39             : {
      40             : 
      41             : }
      42           1 : END_TEST
      43             : 
      44           1 : START_TEST(check_read_json)
      45             : {
      46             :    char basePATH[1024];
      47           1 :    sprintf(basePATH,"./test_check_read_cjson");
      48             : 
      49             : 
      50             :    //clean
      51           1 :    _rmdir(basePATH,"");
      52           1 :    _mkdir("/public",basePATH);
      53             : 
      54           1 :    cJSON * g=cJSON_CreateObject();
      55           1 :    cJSON_AddItemToObject(g,"name" , cJSON_CreateString("0.1.4"));
      56           1 :    char * release_print=cJSON_Print(g);
      57           1 :    debug("going to write release.json\n");
      58           1 :    write_test_file(basePATH,"/public", "release.json", release_print);
      59           1 :    free(release_print);
      60           1 :    cJSON_Delete(g);
      61             : 
      62             :    cJSON * release;
      63             :    // ok, normal
      64             : 
      65             :    // cJSON * read_json(void * opaque, const char * base_path,const char * sub_path,const char * filename)
      66             : 
      67           1 :    release=read_json(NULL,basePATH,"/public/","release.json");
      68           1 :    ck_assert_ptr_ne(release,NULL);
      69           1 :    cJSON_Delete(release);
      70             : 
      71             :    // safety checks:
      72             : 
      73           1 :    release=read_json(NULL,basePATH,"/public/",NULL);
      74           2 :    ck_assert_ptr_eq(release,NULL);
      75             : 
      76           1 :    release=read_json(NULL,basePATH,"/public/","");
      77           2 :    ck_assert_ptr_eq(release,NULL);
      78             : 
      79           1 :    release=read_json(NULL,basePATH,NULL,"release.json");
      80           2 :    ck_assert_ptr_eq(release,NULL);
      81             : 
      82             : 
      83           1 :    release=read_json(NULL,NULL,"/public/","release.json");
      84           2 :    ck_assert_ptr_eq(release,NULL);
      85             : 
      86             : 
      87             :    // file not exists
      88           1 :    release=read_json(NULL,basePATH,"/public/","notexist.json");
      89           2 :    ck_assert_ptr_eq(release,NULL);
      90             : 
      91             :    // not a jason file
      92           1 :    write_test_file(basePATH,"/public", "release.json","# hallo I'm not a json file");
      93           1 :    release=read_json(NULL,basePATH,"/public/","release.json");
      94           2 :    ck_assert_ptr_eq(release,NULL);
      95           1 :    _rmdir(basePATH,"");
      96             : }
      97           1 : END_TEST
      98             : 
      99             : 
     100           3 : Suite * test_suite(void)
     101             : {
     102             :         Suite *s;
     103             :         TCase *tc_core;
     104             :         //TCase *tc_progress;
     105           3 :         s = suite_create("test_repo_io");
     106             :         /* Core test case */
     107           3 :         tc_core = tcase_create("Core");
     108             :         //tcase_add_checked_fixture(tc_core, setup, teardown);
     109           3 :         tcase_add_unchecked_fixture(tc_core, NULL,NULL);
     110           3 :         tcase_set_timeout(tc_core,15);
     111             : 
     112           3 :    tcase_add_test(tc_core, check_read_json);
     113           3 :    tcase_add_test(tc_core, check_JSON_dir_list_x);
     114             : 
     115             : 
     116           3 :         suite_add_tcase(s, tc_core);
     117           3 :         return s;
     118             : }
     119             : 
     120             : 
     121           3 : int main(void)
     122             : {
     123             :         int number_failed;
     124             :         Suite *s;
     125             :         SRunner *sr;
     126             : 
     127           3 :         s = test_suite();
     128           3 :         sr = srunner_create(s);
     129           3 :         srunner_run_all(sr, CK_VERBOSE);
     130           1 :         number_failed = srunner_ntests_failed(sr);
     131           1 :         srunner_free(sr);
     132           1 :         return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     133             : }

Generated by: LCOV version 1.10