"Fossies" - the Fresh Open Source Software Archive

Member "ftwin-master/check/check_ft_file.c" (15 Feb 2015, 3612 Bytes) of package /linux/privat/ftwin-master.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2007 Fran├žois Pesce : francois.pesce (at) gmail (dot) com
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  * 
    8  *  http://www.apache.org/licenses/LICENSE-2.0
    9  * 
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 #include <unistd.h>
   18 #include <stdlib.h>
   19 #include <check.h>
   20 
   21 #include "checksum.h"
   22 #include "debug.h"
   23 #include "ft_file.h"
   24 
   25 extern apr_pool_t *main_pool;
   26 apr_pool_t *pool;
   27 
   28 static void setup(void)
   29 {
   30     apr_status_t rs;
   31 
   32     rs = apr_pool_create(&pool, main_pool);
   33     if (rs != APR_SUCCESS) {
   34     DEBUG_ERR("Error creating pool");
   35     exit(1);
   36     }
   37 }
   38 
   39 static void teardown(void)
   40 {
   41     apr_pool_destroy(pool);
   42 }
   43 
   44 static const char *fname1 = CHECK_DIR "/tests/truerand";
   45 static apr_off_t size1 = 16384;
   46 static const char *fname2 = CHECK_DIR "/tests/copyrand";
   47 static const char *fname3 = CHECK_DIR "/tests/testrand";
   48 
   49 START_TEST(test_checksum_file)
   50 {
   51     apr_status_t status;
   52     apr_uint32_t val_array[HASHSTATE];
   53     apr_uint32_t val_array2[HASHSTATE];
   54     int rv;
   55 
   56     status = checksum_file(fname1, size1, 2 * size1, val_array, pool);
   57     fail_unless(APR_SUCCESS == status, "checksum small file failed");
   58     status = checksum_file(fname2, size1, 2 * size1, val_array2, pool);
   59     fail_unless(APR_SUCCESS == status, "checksum big file failed");
   60     rv = memcmp(val_array, val_array2, HASHSTATE);
   61     fail_unless(0 == rv, "mismatching checksums");
   62 
   63     status = checksum_file(fname3, size1, 2 * size1, val_array2, pool);
   64     fail_unless(APR_SUCCESS == status, "checksum big file failed");
   65     rv = memcmp(val_array, val_array2, HASHSTATE);
   66     fail_unless(0 != rv, "unexpected matching checksums");
   67 
   68     status = checksum_file(fname1, size1, size1 / 2, val_array, pool);
   69     fail_unless(APR_SUCCESS == status, "checksum small file failed");
   70     status = checksum_file(fname2, size1, size1 / 2, val_array2, pool);
   71     fail_unless(APR_SUCCESS == status, "checksum big file failed");
   72     rv = memcmp(val_array, val_array2, HASHSTATE);
   73     fail_unless(0 == rv, "mismatching checksums");
   74 
   75     status = checksum_file(fname3, size1, size1 / 2, val_array2, pool);
   76     fail_unless(APR_SUCCESS == status, "checksum big file failed");
   77     rv = memcmp(val_array, val_array2, HASHSTATE);
   78     fail_unless(0 != rv, "unexpected matching checksums");
   79 }
   80 /* *INDENT-OFF* */
   81 END_TEST
   82 /* *INDENT-ON* */
   83 
   84 START_TEST(test_filecmp)
   85 {
   86     int rv;
   87     apr_status_t status;
   88 
   89     status = filecmp(pool, fname1, fname2, size1, 2 * size1, &rv);
   90     fail_unless(APR_SUCCESS == status, "filecmp small file failed");
   91     status = filecmp(pool, fname1, fname2, size1, size1 / 2, &rv);
   92     fail_unless((APR_SUCCESS == status) && (0 == rv), "filecmp big file failed");
   93 
   94     status = filecmp(pool, fname1, fname3, size1, size1 / 2, &rv);
   95     fail_unless((APR_SUCCESS == status) && (0 != rv), "filecmp big file failed");
   96 }
   97 /* *INDENT-OFF* */
   98 END_TEST
   99 /* *INDENT-ON* */
  100 
  101 Suite *make_ft_file_suite(void)
  102 {
  103     Suite *s;
  104     TCase *tc_core;
  105     s = suite_create("Ft_File");
  106     tc_core = tcase_create("Core Tests");
  107 
  108     tcase_add_checked_fixture(tc_core, setup, teardown);
  109     tcase_add_test(tc_core, test_checksum_file);
  110     tcase_add_test(tc_core, test_filecmp);
  111     suite_add_tcase(s, tc_core);
  112 
  113     return s;
  114 }