LUMIERA.clone/tests/library/test/temp-dir-test.cpp
Ichthyostega 806db414dd Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
 * there is no entity "Lumiera.org" which holds any copyrights
 * Lumiera source code is provided under the GPL Version 2+

== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''

The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!

The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00

120 lines
3.4 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
TempDir(Test) - verify automated temporary working directory
Copyright (C)
2024, Hermann Vosseler <Ichthyostega@web.de>
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
* *****************************************************************/
/** @file temp-dir-test.cpp
** unit test \ref TempDir_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/test/temp-dir.hpp"
#include <fstream>
namespace lib {
namespace test{
namespace test{
/***************************************************************//**
* @test validate proper behaviour of a temporary working directory,
* including automatic name allocation and clean-up.
* @see temp-dir.hpp
* @see DataCSV_test usage example
*/
class TempDir_test : public Test
{
void
run (Arg)
{
simpleUsage();
verify_Lifecycle();
}
void
simpleUsage()
{
TempDir temp;
auto ff = temp.makeFile();
CHECK (fs::exists (ff));
CHECK (fs::is_empty (ff));
std::ofstream out{ff, std::ios_base::out};
auto scree = randStr(55);
out << scree << std::endl;
out.close();
CHECK (fs::is_regular_file (ff));
CHECK (not fs::is_empty (ff));
std::ifstream in{ff};
string readBack;
in >> readBack;
CHECK (readBack == scree);
}
/** @test automatic clean-up even in case of errors. */
void
verify_Lifecycle ()
{
fs::path d1;
fs::path d2;
{
TempDir tt;
d1 = tt;
tt.makeFile("huibuh");
tt.makeFile("huibuh");
tt.makeFile("huibuh");
std::ofstream boo{d1 / "huibuh"};
boo << "boo";
fs::create_directories(d1 / "bug/bear");
fs::rename (d1 / "huibuh", d1 / "bug/bear/fray");
auto scare = [&]{
TempDir tt;
d2 = tt;
tt.makeFile("Mooo");
CHECK (fs::exists(d2 / "Mooo"));
CHECK (not fs::is_empty(d2));
fs::create_directory(d2 / "Mooo"); // Booom!
};
CHECK (d2.empty());
CHECK (not d1.empty());
VERIFY_FAIL ("File exists", scare() );
// nested context was cleaned-up after exception
CHECK (not fs::exists(d2));
CHECK ( fs::exists(d1));
CHECK (not d2.empty());
CHECK (d1 != d2);
boo << "moo";
boo.close();
CHECK (6 == fs::file_size(d1 / "bug/bear/fray"));
// so bottom line: can do filesystem stuff for real...
}
// All traces are gone...
CHECK (not fs::exists(d1));
CHECK (not fs::exists(d2));
}
};
LAUNCHER (TempDir_test, "unit common");
}}} // namespace lib::test::test