Skip to content

Commit 6b6af75

Browse files
committed
wrote unit test to validate string table in standalone (no MUI) format
1 parent 4303d59 commit 6b6af75

15 files changed

Lines changed: 79 additions & 8 deletions

File tree

libmsstyle/VisualStyle.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ public int NumProperties
3737
}
3838

3939
private Dictionary<int, string> m_stringTable;
40-
public Dictionary<int, string> StringTable
40+
public Dictionary<int, string> PreferredStringTable
4141
{
4242
get { return m_stringTable; }
4343
}
4444

4545
private Dictionary<int, Dictionary<int, string>> m_stringTables = new Dictionary<int, Dictionary<int, string>>();
4646

47+
public Dictionary<int, Dictionary<int, string>> StringTables
48+
{
49+
get { return m_stringTables; }
50+
}
51+
4752
private Dictionary<StyleResource, string> m_resourceUpdates;
4853

4954
private ushort m_resourceLanguage;

libmsstyleTests/LoadSaveConsistency.cs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using libmsstyle;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using System;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using System.Drawing;
67
using System.IO;
@@ -19,22 +20,45 @@ public class LoadSaveConsistency
1920
[DataRow(@"..\..\..\styles\w10_1709_aero.msstyles")]
2021
[DataRow(@"..\..\..\styles\w10_1809_aero.msstyles")]
2122
[DataRow(@"..\..\..\styles\w10_1903_aero.msstyles")]
23+
[DataRow(@"..\..\..\styles\w10_2004_aero\aero.msstyles")]
2224
[DataRow(@"..\..\..\styles\w10_20h2_aero.msstyles")]
2325
[DataRow(@"..\..\..\styles\w11_pre_aero.msstyles")]
24-
public void VerifyLoadSave(string file)
26+
[DataRow(@"..\..\..\styles\w11_pre_aero.msstyles", true)]
27+
public void VerifyLoadSave(string file, bool standalone = false)
2528
{
2629
using(var original = new VisualStyle())
2730
using(var saved = new VisualStyle())
2831
{
2932
original.Load(file);
30-
original.Save("tmp.msstyles");
33+
original.Save("tmp.msstyles", standalone);
3134
saved.Load("tmp.msstyles");
3235

3336
bool result = CompareStyles(original, saved);
3437
Assert.IsTrue(result);
3538
}
3639
}
3740

41+
42+
[DataTestMethod]
43+
[DataRow(@"..\..\..\styles\w10_2004_aero\aero.msstyles", true)]
44+
public void VerifyLoadSave_WithStringTable(string file, bool standalone)
45+
{
46+
using (var original = new VisualStyle())
47+
using (var saved = new VisualStyle())
48+
{
49+
original.Load(file);
50+
original.Save("tmp.msstyles", standalone);
51+
saved.Load("tmp.msstyles");
52+
53+
bool result = CompareStyles(original, saved);
54+
Assert.IsTrue(result);
55+
56+
bool sresult = CompareStringTables(original.StringTables, saved.StringTables);
57+
Assert.IsTrue(sresult);
58+
}
59+
}
60+
61+
3862
[TestCleanup]
3963
public void TestCleanup()
4064
{
@@ -147,5 +171,47 @@ bool CompareStyles(VisualStyle s1, VisualStyle s2)
147171

148172
return result;
149173
}
174+
175+
176+
bool CompareStringTables(Dictionary<int, Dictionary<int, string>> s1, Dictionary<int, Dictionary<int, string>> s2)
177+
{
178+
bool result = true;
179+
180+
// for all languages in the original style
181+
foreach (var langTable in s1)
182+
{
183+
// see if there is a table in the other one
184+
Dictionary<int, string> s2table;
185+
if (s2.TryGetValue(langTable.Key, out s2table))
186+
{
187+
// foreach entry in the languages string table
188+
foreach (var entry in langTable.Value)
189+
{
190+
// see if the entry exists and matches in the other one
191+
string s2tablevalue;
192+
if (s2table.TryGetValue(entry.Key, out s2tablevalue))
193+
{
194+
if(!entry.Value.Equals(s2tablevalue))
195+
{
196+
LogMessage(ConsoleColor.DarkRed, "For language {0}, entry {1} mismatches\r\n", langTable.Key, entry.Key);
197+
result = false;
198+
}
199+
}
200+
else
201+
{
202+
LogMessage(ConsoleColor.DarkRed, "For language {0}, entry {1} is missing!\r\n", langTable.Key, entry.Key);
203+
result = false;
204+
}
205+
}
206+
}
207+
else
208+
{
209+
LogMessage(ConsoleColor.DarkRed, "Missing string table for language {0}\r\n", langTable.Key);
210+
result = false;
211+
}
212+
}
213+
214+
return result;
215+
}
150216
}
151217
}
Binary file not shown.
Binary file not shown.
1.26 MB
Binary file not shown.
842 KB
Binary file not shown.
4.5 KB
Binary file not shown.
Binary file not shown.
4.5 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)