Skip to content

Commit

Permalink
Added file example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymoteusz Blazejczyk committed Feb 16, 2017
1 parent bb30294 commit 4d76e22
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 16 deletions.
16 changes: 0 additions & 16 deletions include/utest/test_writer/file.hpp
Expand Up @@ -103,22 +103,6 @@ File::File(FILE* file) noexcept :
m_file{file}
{ }

inline
File::File(const TestString& file, Mode mode) noexcept :
m_open{true}
{
switch (mode) {
case WRITE:
m_file = std::fopen(file.data(), "w");
break;
case APPEND:
m_file = std::fopen(file.data(), "a");
break;
default:
break;
}
}

}
}

Expand Down
15 changes: 15 additions & 0 deletions src/utest/test_writer/file.cpp
Expand Up @@ -43,6 +43,21 @@

using utest::test_writer::File;

File::File(const TestString& file, Mode mode) noexcept :
m_open{true}
{
switch (mode) {
case WRITE:
m_file = std::fopen(file.data(), "w");
break;
case APPEND:
m_file = std::fopen(file.data(), "a");
break;
default:
break;
}
}

void File::write(const TestString& str) noexcept {
if (m_file) {
std::fwrite(str.data(), sizeof(TestString::value_type),
Expand Down
18 changes: 18 additions & 0 deletions tests/test_writer/CMakeLists.txt
Expand Up @@ -30,3 +30,21 @@
if (UNIX)
add_subdirectory(linux)
endif()

add_executable(test-writer-file
file.cpp
)

set_target_properties(test-writer-file PROPERTIES OUTPUT_NAME test_writer_file)
target_link_libraries(test-writer-file utest)

if (DEFINED TEST_RUNNER)
add_test(NAME test-writer-file COMMAND
${CMAKE_BINARY_DIR}/tests/test_writer_file)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(file.cpp PROPERTIES
COMPILE_FLAGS "-Wno-global-constructors"
)
endif()
72 changes: 72 additions & 0 deletions tests/test_writer/file.cpp
@@ -0,0 +1,72 @@
/*!
* @copright
* Copyright (c) 2017, Tymoteusz Blazejczyk
* All rights reserved.
*
* @copright
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* @copright
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* @copright
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* @copright
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* @copright
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file tests/file.cpp
*
* @brief Main implementation
*/

#include <utest/utest.hpp>
#include <utest/test_writer/file.hpp>

#include <memory>

using namespace utest;

int main() {
{
test_writer::File file{"test"};
}
{
test_writer::File file{"test", test_writer::File::WRITE};
}
{
test_writer::File file{"test", test_writer::File::APPEND};
}
{
int mode = 2;

test_writer::File file{"test",
static_cast<test_writer::File::Mode>(mode)};
}
{
std::unique_ptr<test_writer::File> ptr{new test_writer::File{}};
}

return EXIT_SUCCESS;
}

static TestRunner g([] (TestSuite&) { });

0 comments on commit 4d76e22

Please sign in to comment.