-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathExtractedTypeTreeTests.cs
More file actions
121 lines (98 loc) · 3.96 KB
/
Copy pathExtractedTypeTreeTests.cs
File metadata and controls
121 lines (98 loc) · 3.96 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Data.Sqlite;
using NUnit.Framework;
namespace UnityDataTools.UnityDataTool.Tests;
#pragma warning disable NUnit2005, NUnit2006
public class ExtractedTypeTreeTests
{
private string m_TestOutputFolder;
private string m_DataFolder;
private string m_SerializedFile;
private string m_SerializedFilePath;
private string m_TypeTreeDataFile;
[OneTimeSetUp]
public void OneTimeSetup()
{
m_TestOutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "test_folder_typetree");
Directory.CreateDirectory(m_TestOutputFolder);
m_DataFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "ExtractedTypeTree");
m_SerializedFile = "sfwithextractedtypetrees1";
m_SerializedFilePath = Path.Combine(m_DataFolder, m_SerializedFile);
m_TypeTreeDataFile = Path.Combine(m_DataFolder, "sfwithextractedtypetrees1.typetreedata");
}
[SetUp]
public void Setup()
{
Directory.SetCurrentDirectory(m_TestOutputFolder);
}
[TearDown]
public void Teardown()
{
SqliteConnection.ClearAllPools();
foreach (var file in new DirectoryInfo(m_TestOutputFolder).EnumerateFiles())
{
file.Delete();
}
foreach (var dir in new DirectoryInfo(m_TestOutputFolder).EnumerateDirectories())
{
dir.Delete(true);
}
}
[Test]
public async Task Analyze_WithTypeTreeData_DatabaseCorrect(
[Values("-d", "--typetree-data")] string option)
{
var databasePath = SQLTestHelper.GetDatabasePath(m_TestOutputFolder);
Assert.AreEqual(0, await Program.Main(new string[] { "analyze", m_DataFolder, option, m_TypeTreeDataFile }));
using var db = SQLTestHelper.OpenDatabase(databasePath);
var objectCount = SQLTestHelper.QueryInt(db, "SELECT COUNT(*) FROM objects");
Assert.Greater(objectCount, 0, "Expected objects in database when TypeTree data file is provided");
}
[Test]
public async Task Analyze_WithoutTypeTreeData_ReportsFailure()
{
var databasePath = SQLTestHelper.GetDatabasePath(m_TestOutputFolder);
using var swOut = new StringWriter();
using var swErr = new StringWriter();
var currentOut = Console.Out;
var currentErr = Console.Error;
try
{
Console.SetOut(swOut);
Console.SetError(swErr);
await Program.Main(new string[] { "analyze", m_DataFolder });
var output = swOut.ToString() + swErr.ToString();
Assert.That(output, Does.Contain("Failed files: 1"),
"Expected failure when analyzing without TypeTree data file");
}
finally
{
Console.SetOut(currentOut);
Console.SetError(currentErr);
}
}
[Test]
public async Task Dump_WithTypeTreeData_Succeeds(
[Values("-d", "--typetree-data")] string option)
{
Assert.AreEqual(0, await Program.Main(new string[] { "dump", m_SerializedFilePath, "-o", m_TestOutputFolder, option, m_TypeTreeDataFile }));
var outputFile = Path.Combine(m_TestOutputFolder, m_SerializedFile + ".txt");
var txt = File.ReadAllText(outputFile);
// Confirm that the file contains an expected line (based on the content of this file)
Assert.IsTrue(txt.Contains("m_GameObject (PPtr<GameObject>)"));
File.Delete(outputFile);
}
[Test]
public async Task Dump_WithoutTypeTreeData_Fails()
{
Assert.AreNotEqual(0, await Program.Main(new string[] { "dump", m_SerializedFilePath }));
}
[Test]
public async Task TypeTreeData_FileNotFound_ReturnsError()
{
var result = await Program.Main(new string[] { "analyze", m_DataFolder, "--typetree-data", "nonexistent_file.bin" });
Assert.AreNotEqual(0, result, "Expected non-zero return code when TypeTree data file does not exist");
}
}