mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
Fixes for Athenasub and new tests.
Originally committed to SVN as r2457.
This commit is contained in:
parent
99513b7c27
commit
4e00a692be
@ -55,8 +55,8 @@ namespace Athenasub {
|
|||||||
String(const char* utf8);
|
String(const char* utf8);
|
||||||
String(const char* utf8,size_t bytes);
|
String(const char* utf8,size_t bytes);
|
||||||
String(const basic_string<Character>& str);
|
String(const basic_string<Character>& str);
|
||||||
String(const wchar_t* utf16);
|
explicit String(const wchar_t* utf16);
|
||||||
String(const wxString& wxstring);
|
explicit String(const wxString& wxstring);
|
||||||
|
|
||||||
wxString GetWxString() const;
|
wxString GetWxString() const;
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ String& String::Trim(bool fromRight)
|
|||||||
n = len - start;
|
n = len - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
*this = substr(start,n);
|
*this = String(substr(start,n));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,27 +176,27 @@ size_t String::Find(Character c) const
|
|||||||
|
|
||||||
String String::Left(size_t n) const
|
String String::Left(size_t n) const
|
||||||
{
|
{
|
||||||
return substr(0,n);
|
return String(substr(0,n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String String::Right(size_t n) const
|
String String::Right(size_t n) const
|
||||||
{
|
{
|
||||||
size_t len = size();
|
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
|
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
|
bool String::StartsWith(const String& string,bool caseSensitive) const
|
||||||
{
|
{
|
||||||
if (caseSensitive) {
|
if (caseSensitive) {
|
||||||
String tmp = substr(0,string.size());
|
String tmp = String(substr(0,string.size()));
|
||||||
return compare(0,string.size(),string) == 0;
|
return compare(0,string.size(),string) == 0;
|
||||||
} else {
|
} else {
|
||||||
return AsciiLower().StartsWith(string.AsciiLower(),true);
|
return AsciiLower().StartsWith(string.AsciiLower(),true);
|
||||||
@ -514,12 +514,12 @@ String String::PrettyFloat(String src)
|
|||||||
// Float to string
|
// Float to string
|
||||||
String String::FloatToString(float src)
|
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)
|
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
|
// Int to string
|
||||||
String String::IntegerToString(int value)
|
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) {
|
if (isUtf8) {
|
||||||
return String(read);
|
return String(read);
|
||||||
} else {
|
} else {
|
||||||
return wxString(read,*conv);
|
return String(wxString(read,*conv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String GetString(wchar_t *read,shared_ptr<wxMBConv> conv,bool isUtf8)
|
String GetString(wchar_t *read,shared_ptr<wxMBConv> conv,bool isUtf8)
|
||||||
{
|
{
|
||||||
(void)conv;
|
(void)conv;
|
||||||
(void)isUtf8;
|
(void)isUtf8;
|
||||||
return wxString(read);
|
return String(read);
|
||||||
}
|
}
|
||||||
inline void Swap(wchar_t &a) {
|
inline void Swap(wchar_t &a) {
|
||||||
char *c = (char*) &a;
|
char *c = (char*) &a;
|
||||||
@ -204,9 +204,14 @@ Athenasub::String TextFileReader::ActuallyReadLine()
|
|||||||
// Read ASCII/UTF-8 line from file
|
// Read ASCII/UTF-8 line from file
|
||||||
else ParseLine<char>(buffer1,file,stringBuffer,conv,false,isUtf8);
|
else ParseLine<char>(buffer1,file,stringBuffer,conv,false,isUtf8);
|
||||||
|
|
||||||
// Remove BOM
|
// Remove BOM (UTF-8 EF BB BF)
|
||||||
size_t startPos = 0;
|
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
|
// Trim
|
||||||
String str = String(stringBuffer);
|
String str = String(stringBuffer);
|
||||||
@ -243,7 +248,7 @@ void TextFileReader::EnsureValid(Athenasub::String enc)
|
|||||||
// Get encoding being used
|
// Get encoding being used
|
||||||
String TextFileReader::GetCurrentEncoding()
|
String TextFileReader::GetCurrentEncoding()
|
||||||
{
|
{
|
||||||
return encoding.c_str();
|
return String(encoding.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ namespace Athenasub {
|
|||||||
String ActuallyReadLine();
|
String ActuallyReadLine();
|
||||||
|
|
||||||
public:
|
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();
|
~TextFileReader();
|
||||||
|
|
||||||
String ReadLineFromFile();
|
String ReadLineFromFile();
|
||||||
|
@ -55,7 +55,7 @@ namespace Athenasub {
|
|||||||
void SetEncoding(String encoding);
|
void SetEncoding(String encoding);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextFileWriter(wxOutputStream &stream,String encoding=_T(""));
|
TextFileWriter(wxOutputStream &stream,String encoding="");
|
||||||
~TextFileWriter();
|
~TextFileWriter();
|
||||||
|
|
||||||
void WriteLineToFile(Athenasub::String line,bool addLineBreak=true);
|
void WriteLineToFile(Athenasub::String line,bool addLineBreak=true);
|
||||||
|
@ -99,7 +99,7 @@ int main()
|
|||||||
cout << "Executing action " << n << " times... ";
|
cout << "Executing action " << n << " times... ";
|
||||||
timer.Start();
|
timer.Start();
|
||||||
for (int i=0;i<n;i++) {
|
for (int i=0;i<n;i++) {
|
||||||
ActionList actions = control->CreateActionList(L"Test");
|
ActionList actions = control->CreateActionList("Test");
|
||||||
Selection selection = control->CreateSelection();
|
Selection selection = control->CreateSelection();
|
||||||
selection->AddRange(Range(0,5000));
|
selection->AddRange(Range(0,5000));
|
||||||
selection->AddRange(Range(4500,5500));
|
selection->AddRange(Range(4500,5500));
|
||||||
|
@ -72,7 +72,7 @@ private:
|
|||||||
void SetEncodingConfiguration();
|
void SetEncodingConfiguration();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextFileReader(Athenasub::String filename,Athenasub::String encoding=_T(""),bool trim=true);
|
TextFileReader(Athenasub::String filename,Athenasub::String encoding="",bool trim=true);
|
||||||
~TextFileReader();
|
~TextFileReader();
|
||||||
|
|
||||||
Athenasub::String ReadLineFromFile();
|
Athenasub::String ReadLineFromFile();
|
||||||
|
@ -65,7 +65,7 @@ private:
|
|||||||
void SetEncoding();
|
void SetEncoding();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextFileWriter(Athenasub::String filename,Athenasub::String encoding=_T(""));
|
TextFileWriter(Athenasub::String filename,Athenasub::String encoding="");
|
||||||
~TextFileWriter();
|
~TextFileWriter();
|
||||||
|
|
||||||
void WriteLineToFile(Athenasub::String line,bool addLineBreak=true);
|
void WriteLineToFile(Athenasub::String line,bool addLineBreak=true);
|
||||||
|
@ -54,22 +54,30 @@ class AthenasubFileTest : public CppUnit::TestFixture {
|
|||||||
private:
|
private:
|
||||||
LibAthenaSub lib;
|
LibAthenaSub lib;
|
||||||
String fileFolder;
|
String fileFolder;
|
||||||
|
Model subs;
|
||||||
|
Controller controller;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setUp()
|
AthenasubFileTest()
|
||||||
{
|
{
|
||||||
fileFolder = "test_files/";
|
fileFolder = "test_files/";
|
||||||
lib = Athenasub::Create("AthenasubTest");
|
lib = Athenasub::Create("AthenasubTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setUp()
|
||||||
|
{
|
||||||
|
subs = lib->CreateModel();
|
||||||
|
controller = subs->CreateController();
|
||||||
|
}
|
||||||
|
|
||||||
void tearDown()
|
void tearDown()
|
||||||
{
|
{
|
||||||
|
subs = Model();
|
||||||
|
controller = Controller();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLoad()
|
void testLoad()
|
||||||
{
|
{
|
||||||
Model subs = lib->CreateModel();
|
|
||||||
Controller controller = subs->CreateController();
|
|
||||||
CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"in_test1.ass","UTF-8"));
|
CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"in_test1.ass","UTF-8"));
|
||||||
ConstModel csubs = subs;
|
ConstModel csubs = subs;
|
||||||
CPPUNIT_ASSERT(csubs->GetSectionCount() == 3);
|
CPPUNIT_ASSERT(csubs->GetSectionCount() == 3);
|
||||||
@ -81,17 +89,14 @@ public:
|
|||||||
|
|
||||||
void testSave()
|
void testSave()
|
||||||
{
|
{
|
||||||
Model subs = lib->CreateModel();
|
CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"in_test1.ass","UTF-8"));
|
||||||
Controller controller = subs->CreateController();
|
|
||||||
controller->LoadFile(fileFolder+"in_test1.ass","UTF-8");
|
|
||||||
CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test1.ass","UTF-8"));
|
CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test1.ass","UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testStableRewrite()
|
void testStableRewrite()
|
||||||
{
|
{
|
||||||
Model subs = lib->CreateModel();
|
CPPUNIT_ASSERT_NO_THROW(controller->LoadFile(fileFolder+"out_test1.ass","UTF-8"));
|
||||||
Controller controller = subs->CreateController();
|
CPPUNIT_ASSERT(subs->GetSectionCount() == 3);
|
||||||
controller->LoadFile(fileFolder+"out_test1.ass","UTF-8");
|
|
||||||
CPPUNIT_ASSERT_NO_THROW(controller->SaveFile(fileFolder+"out_test2.ass","UTF-8"));
|
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+"out_test1.ass",fileFolder+"out_test2.ass"));
|
||||||
CPPUNIT_ASSERT(AreFilesIdentical(fileFolder+"in_test1.ass",fileFolder+"out_test1.ass") == false);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool visual_studio_open_file(char const * filename, unsigned int line);
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
CppUnit::TextUi::TestRunner runner;
|
CppUnit::TextUi::TestRunner runner;
|
||||||
@ -60,7 +57,6 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||||
|
|
||||||
visual_studio_open_file("e:\\Projects\\aegisub\\unit_test\\src\\main.cpp",63);
|
|
||||||
bool result = runner.run("",false);
|
bool result = runner.run("",false);
|
||||||
return result ? 0 : 1;
|
return result ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
|
AdditionalIncludeDirectories="../athenasub/include;../athenasub/include/athenasub;../athenasub/src"
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||||
MinimalRebuild="true"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
@ -114,6 +115,7 @@
|
|||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="2"
|
Optimization="2"
|
||||||
EnableIntrinsicFunctions="true"
|
EnableIntrinsicFunctions="true"
|
||||||
|
AdditionalIncludeDirectories="../athenasub/include;../athenasub/include/athenasub;../athenasub/src"
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
EnableFunctionLevelLinking="true"
|
EnableFunctionLevelLinking="true"
|
||||||
@ -184,6 +186,10 @@
|
|||||||
RelativePath=".\src\athenasub\test_file.cpp"
|
RelativePath=".\src\athenasub\test_file.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\athenasub\test_format_ass.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\athenasub\test_string.cpp"
|
RelativePath=".\src\athenasub\test_string.cpp"
|
||||||
>
|
>
|
||||||
@ -212,10 +218,6 @@
|
|||||||
RelativePath=".\src\utils.h"
|
RelativePath=".\src\utils.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\src\vc_open_test.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user