I have been programming C++ on Linux for a while, but recently moved to a windows 10 computer.
I managed to set up CodeBlocks with w64-mingw.
I have been trying to move programs from linux to windows and I'm having trouble with filenames. For example, I have code to check if files or directories exist, and to create directories. But I get weird results, if a file check comes back as true, then all subsequent file checks come back as true. I have example code, where test.txt and testdir are a file and directory that do not initially exist, but are created by the program. fail.txt and faildir never exist, but my program claims they exist AFTER creating test.txt and testdir. I've seen several questions about checking if files exist on Windows, but I've never run into behavior like this, and I'm not sure what's going on. Does windows fail to reinitialize something when GetFileAttributes() is called? Or have I missed something really basic?
main.cpp
#include <iostream>
#include <fstream>
#include "../include/FileChecker.h"
int main(){
FileChecker fc = FileChecker();
std::cout << "Test Start" << std::endl;
#ifdef _WIN32
std::cout << "OS is windows" << std::endl;
#endif // _WIN32
std::cout << std::endl;
std::cout << "Nothing should exist" << std::endl;
if(fc.file_exists("test.txt")){
std::cout << "test.txt exists." << std::endl;
}else{
std::cout << "test.txt does not exist." << std::endl;
}
if(fc.file_exists("fail.txt")){
std::cout << "fail.txt exists." << std::endl;
}else{
std::cout << "fail.txt does not exist." << std::endl;
}
if(fc.directory_exists("testdir")){
std::cout << "Directory testdir exists." << std::endl;
}else{
std::cout << "Directory testdir does not exist." << std::endl;
}
if(fc.directory_exists("faildir")){
std::cout << "Directory faildir exists." << std::endl;
}else{
std::cout << "Directory faildir does not exist." << std::endl;
}
std::cout << std::endl;
std::cout << "Creating test.txt" << std::endl;
std::ofstream test("test.txt");
test << "HELLO" << std::endl;
test.close();
std::cout << "Only test.txt should exist" << std::endl;
if(fc.file_exists("test.txt")){
std::cout << "test.txt exists." << std::endl;
}else{
std::cout << "test.txt does not exist." << std::endl;
}
if(fc.file_exists("fail.txt")){
std::cout << "fail.txt exists." << std::endl;
}else{
std::cout << "fail.txt does not exist." << std::endl;
}
if(fc.directory_exists("testdir")){
std::cout << "Directory testdir exists." << std::endl;
}else{
std::cout << "Directory testdir does not exist." << std::endl;
}
if(fc.directory_exists("faildir")){
std::cout << "Directory faildir exists." << std::endl;
}else{
std::cout << "Directory faildir does not exist." << std::endl;
}
std::cout << std::endl;
std::cout << "Creating directory testdir" << std::endl;
if(fc.create_directory("testdir")){
std::cout << "Creation Success" << std::endl;
}else{
std::cout << "Creation Failed" << std::endl;
}
std::cout << "Only testdir should exist" << std::endl;
if(fc.directory_exists("testdir")){
std::cout << "Directory testdir exists." << std::endl;
}else{
std::cout << "Directory testdir does not exist." << std::endl;
}
if(fc.directory_exists("faildir")){
std::cout << "Directory faildir exists." << std::endl;
}else{
std::cout << "Directory faildir does not exist." << std::endl;
}
return 0;
}
FileChecker.h
#ifndef FILECHECKER_H
#define FILECHECKER_H
#ifdef _WIN32
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <direct.h>
#endif // _WIN32
#include <string>
class FileChecker
{
public:
FileChecker();
virtual ~FileChecker();
bool file_exists(std::string filename);
bool directory_exists(std::string dirname);
bool create_file(std::string filename);
bool create_directory(std::string dirname);
protected:
private:
};
#endif // FILECHECKER_H
FileChecker.cpp
#include "../include/FileChecker.h"
FileChecker::FileChecker(){
//ctor
}
FileChecker::~FileChecker(){
//dtor
}
#ifdef _WIN32
bool FileChecker::file_exists(std::string filename){
static LPCTSTR szPath = TEXT(filename.c_str());
DWORD dwAttrib = GetFileAttributes(szPath);
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
#endif // _WIN32
#ifdef _WIN32
bool FileChecker::directory_exists(std::string dirname){
static LPCTSTR szPath = TEXT(dirname.c_str());
DWORD dwAttrib = GetFileAttributes(szPath);
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
#endif // _WIN32
#ifdef _WIN32
bool FileChecker::create_directory(std::string dirname){
static LPCTSTR szPath = TEXT(dirname.c_str());
return(CreateDirectory(szPath, NULL));
}
#endif // _WIN32
Output
You should remove all static keyword in your functions.
bool FileChecker::file_exists(std::string filename){
static LPCTSTR szPath = TEXT(filename.c_str()); // <--- [*]
DWORD dwAttrib = GetFileAttributes(szPath);
when file_exists function is called first time, szPath variable is created and initialized pointing to array of characters of filename. When you call file_exists second time, value of szPath is still the same, and points to invalid data (keeps pointer to data of filename object, which was deleted after calling file_exists first time).
You should read about static variables in functions.
Your code here:
bool FileChecker::file_exists(std::string filename){
static LPCTSTR szPath = TEXT(filename.c_str());
DWORD dwAttrib = GetFileAttributes(szPath);
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
TEXT simply casts, it does not perform any sort of conversion. Make it the following instead:
bool FileChecker::file_exists(std::string filename)
{
DWORD dwAttrib = GetFileAttributesA(filename.c_str());
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
Related
I did two months search on the web for a proper file locking mechanism to be used in a C++ program.
I found a lot on "C and fnctl" which I could proof to work. But all really proper working locking mechanism, that I could proof to work in Linux are only based on file descriptors.
As this seems to be something really old fashined and in actual C++17 style of writing C++ code with file- and ip-streams not using that mechanism, I only came up with something that works with using what was presented here:
Not able to ofstream using __gnu_cxx::stdio_filebuf
My Question is, is this really the only mechanism working? To connect both worlds?
I looked in all these books to find anything about fcntl and C++, but was not successful:
[Der C++ Programmierer Cxx20]
(https://www.hanser-elibrary.com/doi/book/10.3139/9783446465510)
[The C++ Programming Language] (https://www.stroustrup.com/C++.html)
[C++ Das Umfassende Handbuch]
(https://www.rheinwerk-verlag.de/c-plusplus-das-umfassende-handbuch/)
[Modern C++ Programming Cookbook Second Edition]
(https://www.packtpub.com/product/modern-c-programming-cookbook-second-edition/9781800208988)
My question to the C++ gurus here is, if I missed something, or if the following code is, today, begin of 2021 the best we could do.
Short explanation of what the code is a proof for:
We have a C++ Code which adds usernames and its LSF-processes to a conf-file, which is read by SSH-server to allow user access to that machine. As at the same time two or more running processes of this code could lead to concurrent attempts of adding or deleting users from this file could occur, we have to proof that proper file locking is preventing that. Without using an extra "access" file, which also could be a solution.
This is some example code I tested:
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include <fcntl.h>
#include <unistd.h>
#include <ext/stdio_filebuf.h>
using namespace std::this_thread; // for sleep_for
int main( ) {
// set unbuffered concole output
std::cout.setf(std::ios::unitbuf);
const char* filename {"testfile.txt"};
// get input from input_from_user
std::string input_from_user_string;
std::cout << "Please give input to change in the file: ";
std::cin >> input_from_user_string;
int add_1_del_2 = 0;
std::cout << "Please give 1 if you want to add to the file or 2 if you want to delete from file: ";
std::cin >> add_1_del_2;
int input_from_user_time;
std::cout << "Please give seconds to wait: ";
std::cin >> input_from_user_time;
// opening file
std::cout << "Opening File" << std::endl;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; //664
int fd;
fd = open(filename, O_RDWR | O_CREAT, mode);
// printing out information about file descriptor
std::cout << " Dexc:" << fd << std::endl;
// generating C++-streams on filedescriptor
__gnu_cxx::stdio_filebuf<char> sourcebufin(fd, std::ios::in);
__gnu_cxx::stdio_filebuf<char> sourcebufout(fd, std::ios::out);
std::istream myfilein(&sourcebufin);
std::ostream myfileout(&sourcebufout);
// -----------
// check for file Locking or exit
// -----------
// creating structure for file locking
struct flock fl;
fl.l_type = F_RDLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
// set file locking for read
fl.l_type = F_RDLCK;
std::cout << "Checking for Lock on file" << std::endl;
// check for file locking on file for read only once
(void) fcntl(fd, F_GETLK, &fl);
if (fl.l_type != F_UNLCK) {
std::cout << "File is locked for reading by process "
<< fl.l_pid
<< ", in status"
<< ((fl.l_type == F_WRLCK) ? 'W' : 'R')
<< ", start="
<< fl.l_start
<< ", end="
<< fl.l_len
<< std::endl;
}
else {
(void) printf("File is unlocked for reading\n");
}
// set file locking for write
fl.l_type = F_WRLCK;
// check for file locking on file for write in a loop
for (int i = 1; i < 11; i++) {
//printf("Checking for lock %d of 10 times...\n", i);
std::cout << "Checking for lock "
<< i
<< " of 10 times..."
<< std::endl;
(void) fcntl(fd, F_GETLK, &fl);
if (fl.l_type != F_UNLCK) {
//(void) printf("File is locked by process %d, in status %c, start=%8ld, end=%8ld\n", fl.l_pid,
// , fl.l_start, fl.l_len);
std::cout << "File is locked by process "
<< fl.l_pid
<< ", in status"
<< ((fl.l_type == F_WRLCK) ? 'W' : 'R')
<< ", start="
<< fl.l_start
<< ", end="
<< fl.l_len
<< std::endl;
sleep(10);
}
else {
(void) printf("File is unlocked\n");
break;
}
}
// -----------
// apply lock for write on file
// -----------
// locking file
std::cout << "Locking file for write" << std::endl;
// set file locking for write again, as checking on lock resets it
fl.l_type = F_WRLCK;
if (fcntl(fd, F_SETLKW, &fl) == -1) {
perror("fcntl");
abort();
}
// -----------
// wait some time
// -----------
std::cout << "Now waiting for " << input_from_user_time << " seconds, keeping the file locked..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(input_from_user_time));
// -----------
// read from file
// -----------
std::cout << "Reading from file... " << std::endl;
myfilein.seekg(0, std::ios::end);
size_t size_before = myfilein.tellg();
myfilein.seekg(0);
std::string filecontent{""};
filecontent.reserve(size_before);
std::cout << "Length of file is: " << size_before << std::endl;
// read full content of file in string "filecontent"
filecontent.assign((std::istreambuf_iterator<char>(myfilein)),
std::istreambuf_iterator<char>());
// -----------
// print output about read data
// -----------
std::cout << "Length of filecontent-string: " << filecontent.size() << std::endl;
std::cout << "Content of File begin" << std::endl;
std::cout << "----------" << std::endl;
std::cout << filecontent << std::endl;
std::cout << "----------" << std::endl;
// -----------
// Apply changes on read in data depending on given input
// -----------
if (add_1_del_2 == 2) {
std::cout << "Runmode: Del" << std::endl;
std::string string_to_delete = input_from_user_string+"\n";
std::string::size_type pos_of_found_substring = filecontent.find(string_to_delete);
if (pos_of_found_substring != std::string::npos) {
filecontent.erase(pos_of_found_substring, string_to_delete.length());
}
else {
}
}
if (add_1_del_2 == 1) {
std::cout << "Runmode: Append" << std::endl;
filecontent.append(input_from_user_string);
}
std::cout << "Content of String after change" << std::endl;
std::cout << "----------" << std::endl;
std::cout << filecontent << std::endl;
std::cout << "----------" << std::endl;
// -----------
// write out to file, truncate before to length of new string
// -----------
std::cout << "Now starting the write out..." << std::endl;
myfilein.seekg(0);
ftruncate(fd,filecontent.length());
myfileout.seekp(0);
myfileout << filecontent;
myfileout.flush();
myfileout.clear();
// -----------
// read from file for a second time and printout content
// -----------
std::cout << "Reading from file again... " << std::endl;
myfilein.seekg(0, std::ios::end);
size_t size_after = myfilein.tellg();
myfilein.seekg(0);
std::string filecontent_after{""};
filecontent_after.reserve(size_after);
std::cout << "Length of file is now: " << size_after << std::endl;
// read full content of file in string "filecontent"
filecontent_after.assign((std::istreambuf_iterator<char>(myfilein)),
std::istreambuf_iterator<char>());
std::cout << "Length of filecontent_after-string: " << filecontent_after.size() << std::endl;
std::cout << "Content of File end" << std::endl;
std::cout << "----------" << std::endl;
std::cout << filecontent_after << std::endl;
std::cout << "----------" << std::endl;
// -----------
// unlocking file and close file
// -----------
printf("Unlocking...\n");
fl.l_type = F_UNLCK;
if (fcntl(fd, F_SETLK, &fl) == -1) {
perror("fcntl");
abort();
}
close(fd);
// -----------
// done
// -----------
std::cout << "done" << std::endl;
exit(0);
}
I ask for your comments on this or perhaps how to improve.
Alexander Bruns
I'm setting a program to create a COM connection from an ocx file.
I'm using visual studio 2019 with debug x86. It correctly generate the .tlh and .tli files.
My failed tests:
Use visualtudio 2017 and 2019
Use CoCreateInstance:
IMachine* machine = NULL;
// this gives the same error:
HRESULT hr2 = CoCreateInstance(CLSID_Machine, NULL, CLSCTX_INPROC_SERVER,
IID_IMachine,
reinterpret_cast<LPVOID*>(&machine));
Replace CLSID_Machine by the _uuidof(IMachine)
Replace CLSID_Machine by the LPCWSTR clsidString
This is a part of my code:
#import "lib.ocx" no_namespace , named_guids
HRESULT hr1 = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
try {
if (SUCCEEDED(hr1))
{
IMachinePtr machineCUPtr;
HRESULT hr2 = machineCUPtr.CreateInstance(CLSID_Machine, NULL,
CLSCTX_INPROC_SERVER); //Failure
if (FAILED(hr2))
{
std::cout << "Fail:" << hr2 << std::endl;
}
else {
std::cout << "Success: " << hr2 << std::endl;
}
}
else {
std::cout << "Fail CoInit: " << std::endl;
}
}
catch (_com_error& e)
{
std::cout << "COM ERROR catched " << std::endl;
std::cout << "Code = %08lx\n" << e.Error() << std::endl;
std::cout << "Meaning = %s\n" << e.ErrorMessage() << std::endl;
std::cout << "Source = %s\n" << (LPCSTR)e.Source() << std::endl;
std::cout << "Description = %s\n" << (LPCSTR)e.Description() << std::endl;
}
CoUninitialize();
}
I still have this error:
Exception raised to 0x00B20768 in myApp.exe : 0xC000000005 : Access
violation during execution at location 0x00B20768.
Edit:
'''
#include <iostream>
#import "libcom.ocx"
using namespace LIBCOM;
int main()
{
CoInitialize(NULL);
IMachinePtr machineCUPtr(__uuidof(Machine)); //Same error
machineCUPtr->MyMethod(parameters of the method);
CoUninitialize();
return 0;
}
''''
Aloha,
I'm struggling with OpenCL child kernel feature.
Kernel SRC (Minimal example):
kernel void launcher()
{
ndrange_t ndrange = ndrange_1D(1);
enqueue_kernel(get_default_queue(), CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
^{
size_t id = get_global_id(0);
}
);
}
stdafx.h:
#pragma once
#define __CL_ENABLE_EXCEPTIONS
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_TARGET_OPENCL_VERSION 200
#include "targetver.h"
#include <CL/cl2.hpp>
#include <iostream>
#include <string>
Full SRC (Minimal):
#include "stdafx.h"
std::string kernel2_source(
"kernel void launcher() ""\n"
"{ ""\n"
" ndrange_t ndrange = ndrange_1D(1);""\n"
" enqueue_kernel(get_default_queue(), CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,""\n"
" ^{""\n"
" size_t id = get_global_id(0);""\n"
" }""\n"
" );""\n"
"}""\n");
//Number of Input Elements
constexpr int numTriangles = 10;
cl_int errorcode = CL_BUILD_ERROR; //Has to be set to build error, because errorcode isn't set when exception occurs
//Move variable definitions out of main for test purposes;
//Numerous definitions
cl::Program program;
std::vector<cl::Device> devices;
std::vector<cl::Platform> platforms;
cl::CommandQueue queue;
cl::Program::Sources source{ kernel2_source };
int main() {
try {
// Query for platforms
cl::Platform::get(&platforms);
std::cout << "Num Platforms: " << platforms.size() << std::endl;
// Get a list of devices on this platform
platforms[0].getDevices(CL_DEVICE_TYPE_ALL, &devices);
std::cout << "Using platform: " << platforms[0].getInfo<CL_PLATFORM_NAME>() << std::endl;
std::cout << "Num Devices: " << devices.size() << std::endl;
// Create a context for the devices
std::cout << "Using device: " << devices[0].getInfo<CL_DEVICE_NAME>() << std::endl;
//Create a context for the first device
//cl::Context context({ devices[0]});
cl::Context context({ devices[0] });
// Create a command−queue for the first device
queue = cl::CommandQueue(context, devices[0]);
cl::DeviceCommandQueue deviceQueue;
deviceQueue = cl::DeviceCommandQueue(context, devices[0]);
// Create the program from the source code
program = cl::Program(context, source);
std::cout << "Building Program" << std::endl;
// Build the program for the devices
errorcode = program.build("-cl-std=CL2.0 -g");
std::cout << "Success!" << std::endl;
cl::Kernel kernel = cl::Kernel(program, "launcher");
cl::NDRange global = numTriangles;
cl::NDRange local = 1;
queue.enqueueNDRangeKernel(kernel, cl::NullRange, global, local);
std::cout << "finished" << std::endl;
std::cin.get();
}
catch (cl::Error error)
{
std::cout << "Error!" << std::endl;
std::cout << error.what() << "(" << error.err() << ")" << std::endl;
std::cout << "Errorcode: " << errorcode << std::endl;
if (errorcode != CL_SUCCESS) { //...
std::cout << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(devices[0]) << std::endl;
//std::cout << "Build Status: " << program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(devices[1]) << std::endl;
std::cout << "Build Options:" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(devices[0]) << std::endl;
//std::cout << "Build Options:" << program.getBuildInfo<CL_PROGRAM_BUILD_OPTIONS>(devices[1]) << std::endl;
std::cout << "Build Log:" << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]) << std::endl;
//std::cout << "Build Log:" << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[1]) << std::endl;
}
}
std::cin.get();
return 0;
}
Output:
Num Platforms: 1
Using platform: AMD Accelerated Parallel Processing
Num Devices: 2
Using device: Hawaii
Building Program
=> Exception.
There appears an uncaught exception which is strange, because all build error should be caught.
The ndrange_1D(1) is just for testing purposes (and to produce an acceptable amount of dummy output).
The device (AMD R9 390X) is OpenCL 2.0 capable.
Any ideas how to fix this?
EDIT:
Even not using exceptions and using errorcodes throws this an exception!
so i have this code for checking crc file named map.spak and compare the result with my specified crc result which stored in variable "compare"
int main(int iArg, char *sArg[])
{
char sSourceFile[MAX_PATH];
memset(sSourceFile, 0, sizeof(sSourceFile));
CCRC32 crc32;
crc32.Initialize(); //Only have to do this once.
unsigned int iCRC = 0;
strcpy(sSourceFile, "map.spak");
int compare = 399857339;
ifstream checkfile(sSourceFile);
if (checkfile){
cout << "Checking file " << sSourceFile << "..." << endl;
crc32.FileCRC(sSourceFile, &iCRC);
if(iCRC == compare){
cout << "File " << sSourceFile << " complete!\nCRC Result: " << iCRC << endl;
}else{
cout << "File " << sSourceFile << " incomplete!\nCRC Result: " << iCRC << endl;
}
}else{
cout << "File not found!" << endl;
}
system("pause");
return 0;
}
and now i want to make this code for multiple file
let's say the file name list stored in filelist.txt
the filelist.txt structure:
id|filename|specified crc
1|map.spak|399857339
2|monster.spak|274394072
how to make the crc check, loop for each file name
i'm not really good at c++ i only know some algorithm because i know PHP
c++ is too complicated
this is the full source included CRC source Source Code
or pastebin
TestApp.cpp link
I made several changes to your code. I removed guard headers since we use it only in header files. Old-fasioned memset has been replaced by operation on strings. I suspect that you need to pass char* to CCRC32 object hence sSourceFile is still const char*. I compiled code except parts with CCRC32.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "../CCRC32.H"
int main(int iArg, char *sArg[])
{
std::vector<std::string> filenames;
// TODO - populate filesnames (paths?)
CCRC32 crc32;
crc32.Initialize(); //Only have to do this once.
for (unsigned int i = 0; i < filenames.size(); i++) {
const char* sSourceFile = filenames[i].c_str();
unsigned int iCRC = 0;
int compare = 399857339; // TODO - you need to change this since you are checking several files
std::ifstream checkfile(sSourceFile);
if (checkfile) {
std::cout << "Checking file " << sSourceFile << "..." << std::endl;
crc32.FileCRC(sSourceFile, &iCRC);
if(iCRC == compare){
std::cout << "File " << sSourceFile << " complete!\nCRC Result: " << iCRC << std::endl;
} else {
std::cout << "File " << sSourceFile << " incomplete!\nCRC Result: " << iCRC << std::endl;
}
} else {
std::cout << "File tidak ditemukan!" << std::endl;
}
}
return 0;
}
I want to unit test the boost filesystem function create_directories() for it's failure case, i.e., when create_directory fails. Can someone please provide any suggestions on how to do this? Another requirement is that the code needs to be cross-platform.
You could try to create a directory in a path to a file:
#include <fstream>
#include <iostream>
#include "boost/filesystem/path.hpp"
#include "boost/filesystem/operations.hpp"
namespace bfs = boost::filesystem;
int main() {
// Create test dir
boost::system::error_code ec;
bfs::path test_root(bfs::unique_path(
bfs::temp_directory_path(ec) / "%%%%-%%%%-%%%%"));
if (!bfs::create_directory(test_root, ec) || ec) {
std::cout << "Failed creating " << test_root << ": " << ec.message() << '\n';
return -1;
}
// Create file in test dir
bfs::path test_file(test_root / "file");
std::ofstream file_out(test_file.c_str());
file_out.close();
if (!bfs::exists(test_file, ec)) {
std::cout << "Failed creating " << test_file << ": " << ec.message() << '\n';
return -2;
}
// Try to create directory in test_file - should fail
bfs::path invalid_dir(test_file / "dir");
if (bfs::create_directory(invalid_dir, ec)) {
std::cout << "Succeeded creating invalid dir " << invalid_dir << '\n';
return -3;
}
// Try to create nested directory in test_file - should fail
bfs::path nested_invalid_dir(invalid_dir / "nested_dir");
if (bfs::create_directories(nested_invalid_dir, ec)) {
std::cout << "Succeeded creating nested invalid dir " << invalid_dir << '\n';
return -4;
}
// Clean up
bfs::remove_all(test_root);
return 0;
}