Line data Source code
1 : 2 : #include "doctest/doctest.h" 3 : #include "IO.h" 4 : 5 : #include "VolumeDescriptor.h" 6 : 7 : using namespace elsa; 8 : using namespace doctest; 9 : TEST_SUITE_BEGIN("io"); 10 : 11 20 : TEST_CASE_TEMPLATE("IO: Testing exception behaviour of read", data_t, float, double) 12 : { 13 10 : WHEN("Trying to read from a string, without an extension") 14 : { 15 4 : CHECK_THROWS_WITH_AS(io::read<data_t>("hello"), 16 : "No extension found in filename (\"hello\")", Error); 17 : } 18 : 19 10 : WHEN("Trying to read from a string, with an unsupported extension") 20 : { 21 4 : CHECK_THROWS_WITH_AS(io::read<data_t>("hello.something"), 22 : "Can not read with unsupported file extension \".something\"", Error); 23 : } 24 : 25 10 : WHEN("Trying to read from a string, with a valid extension") 26 : { 27 : // Only throws as file is not present 28 4 : CHECK_THROWS_WITH_AS(io::read<data_t>("hello.edf"), 29 : "EDF::read: cannot read from 'hello.edf'", Error); 30 : } 31 : 32 10 : WHEN("Trying to read from a string, with an multiple dots") 33 : { 34 : // Only throws as file is not present 35 4 : CHECK_THROWS_WITH_AS(io::read<data_t>("hello.something.edf"), 36 : "EDF::read: cannot read from 'hello.something.edf'", Error); 37 : } 38 8 : } 39 : 40 20 : TEST_CASE_TEMPLATE("IO: Testing exception behaviour of write", data_t, float, double) 41 : { 42 16 : DataContainer<data_t> x(VolumeDescriptor({32, 32})); 43 8 : x = 1; 44 : 45 10 : WHEN("Writing an edf file") 46 : { 47 4 : THEN("it works") { CHECK_NOTHROW(io::write(x, "hellosomething.edf")); } 48 : } 49 : 50 10 : WHEN("Writing an pgm file") 51 : { 52 4 : THEN("it works") { CHECK_NOTHROW(io::write(x, "hellosomething.pgm")); } 53 : } 54 : 55 10 : WHEN("Writing an with an unsupported extension") 56 : { 57 6 : CHECK_THROWS_WITH_AS(io::write(x, "hellosomethingelse.png"), 58 : "Can not write with unsupported file extension \".png\"", Error); 59 : } 60 : 61 10 : WHEN("Writing without an extension given") 62 : { 63 6 : CHECK_THROWS_WITH_AS(io::write(x, "hello"), "No extension found in filename (\"hello\")", 64 : Error); 65 : } 66 8 : } 67 : 68 : TEST_SUITE_END();