| 1 |
# |
| 2 |
# Copyright by The HDF Group. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# This file is part of HDF5. The full HDF5 copyright notice, including |
| 6 |
# terms governing use, modification, and redistribution, is contained in |
| 7 |
# the COPYING file, which can be found at the root of the source code |
| 8 |
# distribution tree, or in https://www.hdfgroup.org/licenses. |
| 9 |
# If you do not have access to either file, you may request a copy from |
| 10 |
# [email protected]. |
| 11 |
# |
| 12 |
# fileCompareTest.cmake compares two files. |
| 13 |
|
| 14 |
# arguments checking |
| 15 |
if (NOT TEST_FOLDER) |
| 16 |
message (FATAL_ERROR "Require TEST_FOLDER to be defined") |
| 17 |
endif () |
| 18 |
if (NOT TEST_ONEFILE) |
| 19 |
message (FATAL_ERROR "Require TEST_ONEFILE the first file to be defined") |
| 20 |
endif () |
| 21 |
if (NOT TEST_TWOFILE) |
| 22 |
message (FATAL_ERROR "Require TEST_TWOFILE the second file to be defined") |
| 23 |
endif () |
| 24 |
if (NOT TEST_FUNCTION) |
| 25 |
message (FATAL_ERROR "Require TEST_FUNCTION (LT,LTEQ,EQ,GTEQ,GT) to be defined") |
| 26 |
endif () |
| 27 |
|
| 28 |
set (TEST_ONE_SIZE 0) |
| 29 |
set (TEST_TWO_SIZE 0) |
| 30 |
set (TEST_ONE_STRING 0) |
| 31 |
set (TEST_TWO_STRING 0) |
| 32 |
set (TEST_ONE_STRING_LEN 0) |
| 33 |
set (TEST_TWO_STRING_LEN 0) |
| 34 |
|
| 35 |
if (TEST_STRINGS STREQUAL "YES") |
| 36 |
# find the length of the first file |
| 37 |
#s1=`cat $ufile | wc -c | sed -e 's/ //g'` |
| 38 |
file (STRINGS ${TEST_FOLDER}/${TEST_ONEFILE} TEST_ONE_STRING) |
| 39 |
string (LENGTH ${TEST_ONE_STRING} TEST_ONE_STRING_LEN) |
| 40 |
|
| 41 |
# Get the size of the second file. |
| 42 |
file (STRINGS ${TEST_FOLDER}/${TEST_TWOFILE} TEST_TWO_STRING) |
| 43 |
string (LENGTH ${TEST_TWO_STRING} TEST_TWO_STRING_LEN) |
| 44 |
|
| 45 |
math (EXPR TEST_STRING_SIZE "${TEST_ONE_STRING_LEN} - ${TEST_TWO_STRING_LEN}" ) |
| 46 |
|
| 47 |
# now compare the outputs |
| 48 |
execute_process ( |
| 49 |
COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_ONEFILE} ${TEST_FOLDER}/${TEST_TWOFILE} |
| 50 |
RESULT_VARIABLE TEST_RESULT |
| 51 |
) |
| 52 |
|
| 53 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 54 |
message (VERBOSE "COMPARE Result: ${TEST_RESULT}: ${TEST_STRING_SIZE}=${TEST_U_STRING_LEN}-${TEST_O_STRING_LEN}") |
| 55 |
endif () |
| 56 |
# if the return value is !=${TEST_EXPECT} bail out |
| 57 |
if (NOT TEST_RESULT EQUAL TEST_EXPECT) |
| 58 |
message (FATAL_ERROR "Failed: The output of ${TEST_FOLDER}/${TEST_ONEFILE} did not match ${TEST_FOLDER}/${TEST_TWOFILE}.\n${TEST_ERROR}") |
| 59 |
endif () |
| 60 |
else () |
| 61 |
if (CMAKE_VERSION VERSION_LESS "3.14.0") |
| 62 |
message (FATAL_ERROR "CANNOT get file size, file command SIZE not supported") |
| 63 |
else () |
| 64 |
file (SIZE ${TEST_FOLDER}/${TEST_ONEFILE} TEST_ONE_SIZE) |
| 65 |
file (SIZE ${TEST_FOLDER}/${TEST_TWOFILE} TEST_TWO_SIZE) |
| 66 |
if (TEST_FUNCTION MATCHES "LT") |
| 67 |
if (TEST_ONE_SIZE LESS TEST_TWO_SIZE) |
| 68 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 69 |
message (VERBOSE "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was less ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 70 |
endif () |
| 71 |
else () |
| 72 |
message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT less ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 73 |
endif () |
| 74 |
elseif (TEST_FUNCTION MATCHES "LTEQ") |
| 75 |
if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) |
| 76 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 77 |
message (VERBOSES "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was less or equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 78 |
endif () |
| 79 |
else () |
| 80 |
message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT less or equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 81 |
endif () |
| 82 |
elseif (TEST_FUNCTION MATCHES "EQ") |
| 83 |
if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) |
| 84 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 85 |
message (VERBOSE "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 86 |
endif () |
| 87 |
else () |
| 88 |
message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 89 |
endif () |
| 90 |
elseif (TEST_FUNCTION MATCHES "GTEQ") |
| 91 |
if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) |
| 92 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 93 |
message (VERBOSE "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was greater or equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 94 |
endif () |
| 95 |
else () |
| 96 |
message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT greater or equal ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 97 |
endif () |
| 98 |
elseif (TEST_FUNCTION MATCHES "GT") |
| 99 |
if (TEST_ONE_SIZE LESS_EQUAL TEST_TWO_SIZE) |
| 100 |
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") |
| 101 |
message (VERBOSE "Passed: The size of ${TEST_FOLDER}/${TEST_ONEFILE} was greater ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 102 |
endif () |
| 103 |
else () |
| 104 |
message (FATAL_ERROR "The size of ${TEST_FOLDER}/${TEST_ONEFILE} was NOT greater ${TEST_FOLDER}/${TEST_TWOFILE}") |
| 105 |
endif () |
| 106 |
else () |
| 107 |
message (FATAL_ERROR "Failed: Incorrect test size compare command provided.\n${TEST_ERROR}") |
| 108 |
endif () |
| 109 |
endif () |
| 110 |
endif () |
| 111 |
|
| 112 |
# everything went fine... |
| 113 |
|