forked from mia/Aegisub
Fixes for Athenasub and new tests.
Originally committed to SVN as r2457.
This commit is contained in:
parent
99513b7c27
commit
4e00a692be
12 changed files with 119 additions and 37 deletions
|
@ -55,8 +55,8 @@ namespace Athenasub {
|
|||
String(const char* utf8);
|
||||
String(const char* utf8,size_t bytes);
|
||||
String(const basic_string<Character>& str);
|
||||
String(const wchar_t* utf16);
|
||||
String(const wxString& wxstring);
|
||||
explicit String(const wchar_t* utf16);
|
||||
explicit String(const wxString& wxstring);
|
||||
|
||||
wxString GetWxString() const;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,14 +116,14 @@ String GetString(char *read,shared_ptr<wxMBConv> 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<wxMBConv> 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<char>(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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -99,7 +99,7 @@ int main()
|
|||
cout << "Executing action " << n << " times... ";
|
||||
timer.Start();
|
||||
for (int i=0;i<n;i++) {
|
||||
ActionList actions = control->CreateActionList(L"Test");
|
||||
ActionList actions = control->CreateActionList("Test");
|
||||
Selection selection = control->CreateSelection();
|
||||
selection->AddRange(Range(0,5000));
|
||||
selection->AddRange(Range(4500,5500));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
74
unit_test/src/athenasub/test_format_ass.cpp
Normal file
74
unit_test/src/athenasub/test_format_ass.cpp
Normal file
|
@ -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 <iostream>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../athenasub/include;../athenasub/include/athenasub;../athenasub/src"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
|
@ -114,6 +115,7 @@
|
|||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="../athenasub/include;../athenasub/include/athenasub;../athenasub/src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
|
@ -184,6 +186,10 @@
|
|||
RelativePath=".\src\athenasub\test_file.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\athenasub\test_format_ass.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\athenasub\test_string.cpp"
|
||||
>
|
||||
|
@ -212,10 +218,6 @@
|
|||
RelativePath=".\src\utils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\vc_open_test.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
|
Loading…
Reference in a new issue