forked from pencil2d/pencil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_objectsaveloader.cpp
82 lines (57 loc) · 2.07 KB
/
test_objectsaveloader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "objectsaveloader.h"
#include "test_objectsaveloader.h"
TestObjectSaveLoader::TestObjectSaveLoader()
{
}
void TestObjectSaveLoader::testCase1()
{
//ObjectSaveLoader* pSaveLoader = new ObjectSaveLoader(this);
QVERIFY2(true, "Failure");
}
void TestObjectSaveLoader::testNotExistFile()
{
ObjectSaveLoader pSaveLoader;
QString strDummyPath = "hahaha_blala.pcl";
Object* pObject = pSaveLoader.load( strDummyPath );
QVERIFY2( pObject == NULL, "File doesn't exist.");
QVERIFY2( pSaveLoader.error().code() == PCL_ERROR_FILE_NOT_EXIST, "" );
}
void TestObjectSaveLoader::testInvalidXML()
{
QString strBadXMLPath = QDir::tempPath() + "/bad.pcl";
QFile badXMLFile( strBadXMLPath );
badXMLFile.open( QIODevice::WriteOnly );
QTextStream fout( &badXMLFile );
fout << "*&%% haha, this is not a xml file.";
badXMLFile.close();
ObjectSaveLoader pSaveLoader;
Object* pObj = pSaveLoader.load( strBadXMLPath );
QVERIFY( pObj == NULL );
QVERIFY( pSaveLoader.error().code() == PCL_ERROR_INVALID_XML_FILE );
}
void TestObjectSaveLoader::testInvalidPencilDocument()
{
QString strBadXMLPath = QDir::tempPath() + "/bad.pcl";
QFile badXMLFile( strBadXMLPath );
badXMLFile.open( QIODevice::WriteOnly );
QTextStream fout( &badXMLFile );
fout << "<!DOCTYPE NotPencilDocument><document></document>";
badXMLFile.close();
ObjectSaveLoader pSaveLoader;
Object* pObj = pSaveLoader.load( strBadXMLPath );
QVERIFY( pObj == NULL );
QVERIFY( pSaveLoader.error().code() == PCL_ERROR_INVALID_PENCIL_FILE );
}
void TestObjectSaveLoader::testMinimalPencilDocument()
{
QString strBadXMLPath = QDir::tempPath() + "/minimal.pcl";
QFile badXMLFile( strBadXMLPath );
badXMLFile.open( QIODevice::WriteOnly );
QTextStream fout( &badXMLFile );
fout << "<!DOCTYPE PencilDocument><document></document>";
badXMLFile.close();
ObjectSaveLoader pSaveLoader;
Object* pObj = pSaveLoader.load( strBadXMLPath );
QVERIFY( pObj != NULL );
QVERIFY( pSaveLoader.error().code() == PCL_OK );
}