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

          Line data    Source code
       1             : /*
       2             :  test_rpm.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             : #include "test-0.1-1.el6.src.rpm.h"
      35             : #include "test-0.1-1.el7.centos.x86_64.rpm.h"
      36             : #include "test-0.1-1.x86_64.rpm.h"
      37             : 
      38           1 : START_TEST(check_normal)
      39             : {
      40             : 
      41             :         char basePATH[1024];
      42             :         char rpmPATH[1024];
      43           1 :         sprintf(basePATH,"./test_check_rpm");
      44             : 
      45             : 
      46             :         //clean
      47           1 :         _rmdir(basePATH,"");
      48           1 :         _mkdir("/projectdir/rpm",basePATH);
      49           1 :         sprintf(rpmPATH,"%s/projectdir/rpm/",basePATH);
      50             : 
      51           1 :         cJSON * g=cJSON_CreateObject();
      52           1 :         cJSON_AddItemToObject(g,"name" , cJSON_CreateString("0.1.4"));
      53           1 :         char * release_print=cJSON_Print(g);
      54           1 :         debug("going to write release.json\n");
      55           1 :         write_test_file(basePATH,"/public", "release.json", release_print);
      56           1 :         free(release_print);
      57           1 :         cJSON_Delete(g);
      58           1 :         cJSON *rpm_info=NULL;
      59             : 
      60             :         int result;
      61             :         // file is null : 1
      62           1 :         result=get_rpm_fileinfo(NULL,rpmPATH , NULL,&rpm_info);
      63           1 :         ck_assert_int_eq(result, RPM_ERR_BADARG);
      64             : 
      65             :         // path is null : 1
      66           1 :         result=get_rpm_fileinfo(NULL,NULL ,"tt",&rpm_info);
      67           2 :         ck_assert_int_eq(result, RPM_ERR_BADARG);
      68             : 
      69           1 :         write_test_file(rpmPATH,"", "test.rpm", "this is no rpm\n");
      70             :         // file is no rpm
      71           1 :         result=get_rpm_fileinfo(NULL,rpmPATH , "test.rpm",&rpm_info);
      72           2 :         ck_assert_int_eq(result, RPM_ERR_READ);
      73             : 
      74             :         // real rpm tests
      75             : 
      76             :         char filename[256];
      77             :         const char * rpm_data;
      78             :         int filelength;
      79             :         int srpm;
      80             : 
      81             :         // test-0.1-1.el6.src.rpm, source rpm
      82             : 
      83           1 :         sprintf(filename,"test-0.1-1.el6.src.rpm");
      84           1 :         rpm_data=test_0_1_1_el6_src_rpm;
      85           1 :         filelength=test_0_1_1_el6_src_rpm_len;
      86           1 :         srpm=0;
      87             : 
      88             : 
      89           1 :         result=write_test_file_n(rpmPATH,"",filename , rpm_data,filelength);
      90           2 :         ck_assert_int_eq(result, filelength);
      91             : 
      92           1 :         result=get_rpm_fileinfo(NULL,rpmPATH , filename,&rpm_info);
      93           2 :         ck_assert_int_eq(result, 0);
      94           2 :         ck_assert_ptr_ne(NULL, rpm_info);
      95           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "name"),"test");
      96           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "version"),"0.1");
      97           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "arch"),"x86_64");
      98           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "distribution"),"el6");
      99           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filename"),filename);
     100           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filepath"),rpmPATH);
     101           2 :         ck_assert_int_eq(cJSON_GetObjectItem(rpm_info, "SRPM")->valueint, srpm);
     102             : 
     103           1 :         cJSON_Delete(rpm_info);
     104           1 :         rpm_info=NULL;
     105             : 
     106             :         // test-0.1-1.el7.centos.x86_64.rpm,
     107             : 
     108           1 :         sprintf(filename,"test-0.1-1.el7.centos.x86_64.rpm");
     109           1 :         filelength=test_0_1_1_el7_centos_x86_64_rpm_len;
     110           1 :         rpm_data=test_0_1_1_el7_centos_x86_64_rpm;
     111           1 :         srpm=0;
     112             : 
     113             : 
     114           1 :         result=write_test_file_n(rpmPATH,"",filename , rpm_data,filelength);
     115           2 :         ck_assert_int_eq(result, filelength);
     116             : 
     117           1 :         result=get_rpm_fileinfo(NULL,rpmPATH , filename,&rpm_info);
     118           2 :         ck_assert_int_eq(result, 0);
     119           2 :         ck_assert_ptr_ne(NULL, rpm_info);
     120           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "name"),"test");
     121           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "version"),"0.1");
     122           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "arch"),"x86_64");
     123           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "distribution"),"el7");
     124           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filename"),filename);
     125           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filepath"),rpmPATH);
     126           2 :         ck_assert_int_eq(cJSON_GetObjectItem(rpm_info, "SRPM")->valueint, srpm);
     127             : 
     128           1 :         cJSON_Delete(rpm_info);
     129           1 :         rpm_info=NULL;
     130             : 
     131             : 
     132             :         // test-0.1-1.x86_64.rpm,
     133             : 
     134           1 :         sprintf(filename,"test-0.1-1.x86_64.rpm");
     135           1 :         filelength=test_0_1_1_x86_64_rpm_len;
     136           1 :         rpm_data=test_0_1_1_x86_64_rpm;
     137           1 :         srpm=0;
     138             : 
     139             : 
     140           1 :         result=write_test_file_n(rpmPATH,"",filename , rpm_data,filelength);
     141           2 :         ck_assert_int_eq(result, filelength);
     142             : 
     143           1 :         result=get_rpm_fileinfo(NULL,rpmPATH , filename,&rpm_info);
     144           2 :         ck_assert_int_eq(result, 0);
     145           2 :         ck_assert_ptr_ne(NULL, rpm_info);
     146           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "name"),"test");
     147           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "version"),"0.1");
     148           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "arch"),"x86_64");
     149           2 :         ck_assert_ptr_eq(cJSON_get_key(rpm_info, "distribution"),NULL);
     150           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filename"),filename);
     151           2 :         ck_assert_str_eq(cJSON_get_key(rpm_info, "filepath"),rpmPATH);
     152           2 :         ck_assert_int_eq(cJSON_GetObjectItem(rpm_info, "SRPM")->valueint, srpm);
     153             : 
     154           1 :         cJSON_Delete(rpm_info);
     155           1 :         rpm_info=NULL;
     156             : 
     157             : 
     158           1 :         _rmdir(basePATH,"");
     159             : 
     160             : }
     161           1 : END_TEST
     162             : 
     163             : 
     164             : 
     165             : 
     166             : 
     167             : 
     168           2 : Suite * test_suite(void)
     169             : {
     170             :         Suite *s;
     171             :         TCase *tc_core;
     172             :         //TCase *tc_progress;
     173           2 :         s = suite_create("test_error");
     174             :         /* Core test case */
     175           2 :         tc_core = tcase_create("Core");
     176             :         //tcase_add_checked_fixture(tc_core, setup, teardown);
     177           2 :         tcase_add_unchecked_fixture(tc_core, NULL,NULL);
     178           2 :         tcase_set_timeout(tc_core,15);
     179           2 :         tcase_add_test(tc_core, check_normal);
     180           2 :         suite_add_tcase(s, tc_core);
     181           2 :         return s;
     182             : }
     183             : 
     184             : 
     185           2 : int main(void)
     186             : {
     187             :         int number_failed;
     188             :         Suite *s;
     189             :         SRunner *sr;
     190             : 
     191           2 :         s = test_suite();
     192           2 :         sr = srunner_create(s);
     193           2 :         srunner_run_all(sr, CK_NORMAL);
     194           1 :         number_failed = srunner_ntests_failed(sr);
     195           1 :         srunner_free(sr);
     196           1 :         return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     197             : }

Generated by: LCOV version 1.10