diff --git a/athenasub/include/athenasub/athenastring.h b/athenasub/include/athenasub/athenastring.h index abd2ebf05..444a0938a 100644 --- a/athenasub/include/athenasub/athenastring.h +++ b/athenasub/include/athenasub/athenastring.h @@ -55,8 +55,8 @@ namespace Athenasub { String(const char* utf8); String(const char* utf8,size_t bytes); String(const basic_string& str); - String(const wchar_t* utf16); - String(const wxString& wxstring); + explicit String(const wchar_t* utf16); + explicit String(const wxString& wxstring); wxString GetWxString() const; diff --git a/athenasub/src/athenastring.cpp b/athenasub/src/athenastring.cpp index a8ca566e9..cadd467ee 100644 --- a/athenasub/src/athenastring.cpp +++ b/athenasub/src/athenastring.cpp @@ -139,7 +139,7 @@ String& String::Trim(bool fromRight) n = len - start; } - *this = substr(start,n); + *this = String(substr(start,n)); return *this; } @@ -176,27 +176,27 @@ size_t String::Find(Character c) const String String::Left(size_t n) const { - return substr(0,n); + return String(substr(0,n)); } String String::Right(size_t n) const { size_t len = size(); - return substr(len-n,n); + return String(substr(len-n,n)); } String String::Mid(size_t start,size_t count) const { - return substr(start,count); + return String(substr(start,count)); } bool String::StartsWith(const String& string,bool caseSensitive) const { if (caseSensitive) { - String tmp = substr(0,string.size()); + String tmp = String(substr(0,string.size())); return compare(0,string.size(),string) == 0; } else { return AsciiLower().StartsWith(string.AsciiLower(),true); @@ -514,12 +514,12 @@ String String::PrettyFloat(String src) // Float to string String String::FloatToString(float src) { - return PrettyFloat(wxString::Format(_T("%f"),src)); + return PrettyFloat(String(wxString::Format(_T("%f"),src))); } String String::FloatToString(double src) { - return PrettyFloat(wxString::Format(_T("%f"),src)); + return PrettyFloat(String(wxString::Format(_T("%f"),src))); } @@ -527,7 +527,7 @@ String String::FloatToString(double src) // Int to string String String::IntegerToString(int value) { - return wxString::Format(_T("%i"),value); + return String(wxString::Format(_T("%i"),value)); } diff --git a/athenasub/src/text_file_reader.cpp b/athenasub/src/text_file_reader.cpp index 93c7836ca..f5fb59bed 100644 --- a/athenasub/src/text_file_reader.cpp +++ b/athenasub/src/text_file_reader.cpp @@ -116,14 +116,14 @@ String GetString(char *read,shared_ptr conv,bool isUtf8) if (isUtf8) { return String(read); } else { - return wxString(read,*conv); + return String(wxString(read,*conv)); } } String GetString(wchar_t *read,shared_ptr conv,bool isUtf8) { (void)conv; (void)isUtf8; - return wxString(read); + return String(read); } inline void Swap(wchar_t &a) { char *c = (char*) &a; @@ -204,9 +204,14 @@ Athenasub::String TextFileReader::ActuallyReadLine() // Read ASCII/UTF-8 line from file else ParseLine(buffer1,file,stringBuffer,conv,false,isUtf8); - // Remove BOM + // Remove BOM (UTF-8 EF BB BF) size_t startPos = 0; - if (stringBuffer.Length() > 0 && stringBuffer[0] == 0xFEFF) startPos = 3; + if (stringBuffer.Length() >= 3) { + int b1 = (unsigned char) stringBuffer[0]; + int b2 = (unsigned char) stringBuffer[1]; + int b3 = (unsigned char) stringBuffer[2]; + if (b1 == 0xEF && b2 == 0xBB && b3 == 0xBF) startPos = 3; + } // Trim String str = String(stringBuffer); @@ -243,7 +248,7 @@ void TextFileReader::EnsureValid(Athenasub::String enc) // Get encoding being used String TextFileReader::GetCurrentEncoding() { - return encoding.c_str(); + return String(encoding.c_str()); } diff --git a/athenasub/src/text_file_reader.h b/athenasub/src/text_file_reader.h index 478509877..2e959ef15 100644 --- a/athenasub/src/text_file_reader.h +++ b/athenasub/src/text_file_reader.h @@ -69,7 +69,7 @@ namespace Athenasub { String ActuallyReadLine(); public: - TextFileReader(wxInputStream &stream,String encoding=_T(""),bool trim=true,bool prefetch=true); + TextFileReader(wxInputStream &stream,String encoding="",bool trim=true,bool prefetch=true); ~TextFileReader(); String ReadLineFromFile(); diff --git a/athenasub/src/text_file_writer.h b/athenasub/src/text_file_writer.h index 52a0905ba..45606f644 100644 --- a/athenasub/src/text_file_writer.h +++ b/athenasub/src/text_file_writer.h @@ -55,7 +55,7 @@ namespace Athenasub { void SetEncoding(String encoding); public: - TextFileWriter(wxOutputStream &stream,String encoding=_T("")); + TextFileWriter(wxOutputStream &stream,String encoding=""); ~TextFileWriter(); void WriteLineToFile(Athenasub::String line,bool addLineBreak=true); diff --git a/athenasub/test/src/main.cpp b/athenasub/test/src/main.cpp index 3c5657e82..77499f529 100644 --- a/athenasub/test/src/main.cpp +++ b/athenasub/test/src/main.cpp @@ -99,7 +99,7 @@ int main() cout << "Executing action " << n << " times... "; timer.Start(); for (int i=0;iCreateActionList(L"Test"); + ActionList actions = control->CreateActionList("Test"); Selection selection = control->CreateSelection(); selection->AddRange(Range(0,5000)); selection->AddRange(Range(4500,5500)); diff --git a/athenasub/test/src/text_file_reader.h b/athenasub/test/src/text_file_reader.h index cf11f515e..768aa9075 100644 --- a/athenasub/test/src/text_file_reader.h +++ b/athenasub/test/src/text_file_reader.h @@ -72,7 +72,7 @@ private: void SetEncodingConfiguration(); public: - TextFileReader(Athenasub::String filename,Athenasub::String encoding=_T(""),bool trim=true); + TextFileReader(Athenasub::String filename,Athenasub::String encoding="",bool trim=true); ~TextFileReader(); Athenasub::String ReadLineFromFile(); diff --git a/athenasub/test/src/text_file_writer.h b/athenasub/test/src/text_file_writer.h index 190efd161..54bc215ce 100644 --- a/athenasub/test/src/text_file_writer.h +++ b/athenasub/test/src/text_file_writer.h @@ -65,7 +65,7 @@ private: void SetEncoding(); public: - TextFileWriter(Athenasub::String filename,Athenasub::String encoding=_T("")); + TextFileWriter(Athenasub::String filename,Athenasub::String encoding=""); ~TextFileWriter(); void WriteLineToFile(Athenasub::String line,bool addLineBreak=true); diff --git a/unit_test/src/athenasub/test_file.cpp b/unit_test/src/athenasub/test_file.cpp index f300ebabe..0b6437604 100644 --- a/unit_test/src/athenasub/test_file.cpp +++ b/unit_test/src/athenasub/test_file.cpp @@ -54,22 +54,30 @@ class AthenasubFileTest : public CppUnit::TestFixture { private: LibAthenaSub lib; String fileFolder; + Model subs; + Controller controller; public: - void setUp() + AthenasubFileTest() { fileFolder = "test_files/"; lib = Athenasub::Create("AthenasubTest"); } + void setUp() + { + subs = lib->CreateModel(); + controller = subs->CreateController(); + } + void tearDown() { + subs = Model(); + controller = Controller(); } void testLoad() { - Model subs = lib->CreateModel(); - Controller controller = subs->CreateController(); CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"in_test1.ass","UTF-8")); ConstModel csubs = subs; CPPUNIT_ASSERT(csubs->GetSectionCount() == 3); @@ -81,17 +89,14 @@ public: void testSave() { - Model subs = lib->CreateModel(); - Controller controller = subs->CreateController(); - controller->LoadFile(fileFolder+"in_test1.ass","UTF-8"); + CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"in_test1.ass","UTF-8")); CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test1.ass","UTF-8")); } void testStableRewrite() { - Model subs = lib->CreateModel(); - Controller controller = subs->CreateController(); - controller->LoadFile(fileFolder+"out_test1.ass","UTF-8"); + CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"out_test1.ass","UTF-8")); + CPPUNIT_ASSERT(subs->GetSectionCount() == 3); CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test2.ass","UTF-8")); CPPUNIT_ASSERT(AreFilesIdentical(fileFolder+"out_test1.ass",fileFolder+"out_test2.ass")); CPPUNIT_ASSERT(AreFilesIdentical(fileFolder+"in_test1.ass",fileFolder+"out_test1.ass") == false); diff --git a/unit_test/src/athenasub/test_format_ass.cpp b/unit_test/src/athenasub/test_format_ass.cpp new file mode 100644 index 000000000..6dc1f70ce --- /dev/null +++ b/unit_test/src/athenasub/test_format_ass.cpp @@ -0,0 +1,74 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// 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 the Aegisub Group 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + +#include "../suites.h" +#include "../utils.h" +#if ATHENASUB_TEST == 1 + +#include +#include +#include +#include "athenasub/athenasub.h" +#include "formats/format_ass.h" +using namespace Athenasub; + + +class AthenasubFormatASSTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(AthenasubFormatASSTest); + CPPUNIT_TEST(testDialogueParse); + CPPUNIT_TEST_SUITE_END(); + +private: + +public: + void setUp() + { + } + + void tearDown() + { + } + + void testDialogueParse() + { + DialogueASS diag; + DialogueASS refDiag; + CPPUNIT_ASSERT_NO_THROW(refDiag = DialogueASS("Dialogue: 3,1:23:45.67,2:34:56.78,style name,actor name,0001,0020,3300,effect field,Text, why halo thar?",1)); + } +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AthenasubFormatASSTest,AegisubSuites::athenasub()); + +#endif diff --git a/unit_test/src/main.cpp b/unit_test/src/main.cpp index f14249d40..45b422d47 100644 --- a/unit_test/src/main.cpp +++ b/unit_test/src/main.cpp @@ -48,9 +48,6 @@ #endif -bool visual_studio_open_file(char const * filename, unsigned int line); - - int main() { CppUnit::TextUi::TestRunner runner; @@ -60,7 +57,6 @@ int main() #endif runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); - visual_studio_open_file("e:\\Projects\\aegisub\\unit_test\\src\\main.cpp",63); bool result = runner.run("",false); return result ? 0 : 1; } diff --git a/unit_test/unit_test.vcproj b/unit_test/unit_test.vcproj index e6b124d72..5a7257d88 100644 --- a/unit_test/unit_test.vcproj +++ b/unit_test/unit_test.vcproj @@ -41,6 +41,7 @@ + + @@ -212,10 +218,6 @@ RelativePath=".\src\utils.h" > - -