diff --git a/src/framework/System.IO.h b/src/framework/System.IO.h new file mode 100644 index 0000000..1579d5a --- /dev/null +++ b/src/framework/System.IO.h @@ -0,0 +1,210 @@ +#ifndef _INCLUDED_SYSTEM_IO_H_ +#define _INCLUDED_SYSTEM_IO_H_ + +#include +#include + +#include "System.h" +#include "Path.h" + +#include "OS.h" + +namespace System +{ + namespace IO + { + class FileInfo + { + System::String m_path; + + public: + FileInfo() + { + } + + FileInfo(const System::String& s) + : m_path(s) + { + String cwd = Environment::CurrentDirectory(); + m_path = System::Path::Combine(cwd, s); + } + + System::String FullName() const + { + return m_path; + } + + bool Exists() const + { + struct stat statStruct; + bool fileExists = + (stat(m_path.str().c_str(), &statStruct) == 0); + return fileExists; + } + + String Extension() const + { + int dotPos = m_path.LastIndexOf('.'); + if (dotPos == -1) { + return String(""); + } + // Extension include the "." + String ext = m_path.Substring(dotPos); + return ext; + } + + String Name() const + { + // from the end of the path back up to the last / or \\ to strip + // to the filename + int lastForwardSlash = m_path.LastIndexOf('/'); + int lastBackwardSlash = m_path.LastIndexOf('\\'); + + if (lastForwardSlash == -1 && lastBackwardSlash == -1) { + return m_path; + } + + if (lastForwardSlash == -1) { + return m_path.Substring(lastBackwardSlash + 1); + } + if (lastBackwardSlash == -1) { + return m_path.Substring(lastForwardSlash + 1); + } + return m_path; + } + + virtual void Delete() + { + int errVal = std::remove(FullName().str().c_str()); + if (errVal) { + // an error occurred TODO perhaps it should throw if not found) + // throw if a directory + static_cast(errVal); + } + return; + } + + DateTime CreationTime() + { + throw System::NotImplementedException("FileInfo::Creation time not implemented"); + } + }; + + class StreamWriter + { + System::String m_file; +#if defined (SUPPORTS_CPLUSPLUS_11) + std::shared_ptr m_fd; +#else + std::ofstream* m_fd; +#endif + bool m_disposed; + + public: + StreamWriter(const System::String& file) + : m_file(file) + , m_disposed(false) + { +#if defined (SUPPORTS_CPLUSPLUS_11) + m_fd = std::shared_ptr(new std::ofstream(file.str().c_str())); +#else + m_fd = new std::ofstream(file.str().c_str()); +#endif + } + + ~StreamWriter() + { + Dispose(); + } + + void WriteLine(const System::String& s) + { + (*m_fd) << s.str() << "\n"; + } + + void Dispose() + { + if (!m_disposed) { + (*m_fd).close(); +#if !defined (SUPPORTS_CPLUSPLUS_11) + delete m_fd; +#endif + m_disposed = true; + } + } + }; + + class FileNotFoundException : public System::Exception + { + public: + FileNotFoundException() + { + } + }; + + class StreamReader + { + System::String m_file; + // TODO C++ 11 (Travis-CI is prevent me from turning this on) +#if defined (SUPPORTS_CPLUSPLUS_11) + std::shared_ptr m_fd; +#else + std::ifstream *m_fd; +#endif + bool m_disposed; + + public: + StreamReader(const System::String& file) + : m_file(file) + , m_disposed(false) + { + FileInfo info(file); + if (!info.Exists()) { + throw System::IO::FileNotFoundException(); + } + + std::string path = info.FullName().str(); + +#if defined (SUPPORTS_CPLUSPLUS_11) + //m_fd = std::shared_ptr(new std::ifstream(path.c_str())); +#else + m_fd = new std::ifstream(path.c_str()); +#endif + } + + ~StreamReader() + { + Dispose(); + } + + System::String ReadLine() + { + std::string strIn; + std::getline((*m_fd), strIn); + + System::String strOut(strIn.c_str()); + return strOut; + } + + void Dispose() + { + if (!m_disposed) { + (*m_fd).close(); +#if !defined (SUPPORTS_CPLUSPLUS_11) + delete m_fd; +#endif + m_disposed = true; + } + } + + bool EndOfStream() + { + return !(*m_fd) || (*m_fd).eof(); + } + }; + } +} + +using namespace System::IO; + +#endif diff --git a/src/googletest/xcode/Samples#FrameworkSample/runtests.sh b/src/googletest/xcode/Samples#FrameworkSample/runtests.sh new file mode 100644 index 0000000..4a0d413 --- /dev/null +++ b/src/googletest/xcode/Samples#FrameworkSample/runtests.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# +# Copyright 2008, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * 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. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# 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 +# OWNER 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. + +# Executes the samples and tests for the Google Test Framework. + +# Help the dynamic linker find the path to the libraries. +export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR +export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR + +# Create some executables. +test_executables=$@ + +# Now execute each one in turn keeping track of how many succeeded and failed. +succeeded=0 +failed=0 +failed_list=() +for test in ${test_executables[*]}; do + "$test" + result=$? + if [ $result -eq 0 ]; then + succeeded=$(( $succeeded + 1 )) + else + failed=$(( failed + 1 )) + failed_list="$failed_list $test" + fi +done + +# Report the successes and failures to the console. +echo "Tests complete with $succeeded successes and $failed failures." +if [ $failed -ne 0 ]; then + echo "The following tests failed:" + echo $failed_list +fi +exit $failed diff --git a/src/unittests/CMakeLists.txt b/src/unittests/CMakeLists.txt index f8a86f8..2a26ed2 100644 --- a/src/unittests/CMakeLists.txt +++ b/src/unittests/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required (VERSION 2.8.7) - # enable CTest unit test runner include( CTest )