LCOV - code coverage report
Current view: top level - elsa/io/tests - test_IO.cpp (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 44 44 100.0 %
Date: 2022-08-25 03:05:39 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14