Repository navigation
Expand file tree
/
Copy pathParserTest.cs
More file actions
72 lines (59 loc) · 1.74 KB
/
Copy pathParserTest.cs
File metadata and controls
72 lines (59 loc) · 1.74 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
using UnityEngine;
using NUnit.Framework;
using BarcodeScanner;
using BarcodeScanner.Parser;
[TestFixture]
public class ParserTest
{
#region Test Failure
[Test]
public void TestErrors()
{
IParser parser = new ZXingParser();
ParserResult result = parser.Decode(new Color32[0], 0, 0);
Assert.IsNull(result);
}
[Test]
public void TestEmpty()
{
IParser parser = new ZXingParser();
var image = Resources.Load<Texture2D>("standard");
ParserResult result = parser.Decode(image.GetPixels32(), image.width, image.height);
Assert.IsNull(result);
}
#endregion
#region Test Barcode Types
private static object[] ImageTests = {
// 1D
new object[] { "code_39", "google"},
new object[] { "code_128", "google"},
new object[] { "code_isbn", "9783161484100" },
// 2D
new object[] { "code_qr", "google"},
new object[] { "code_datamatrix", "google"},
new object[] { "code_aztec", "google"}
};
[Test, TestCaseSource("ImageTests")]
public void TestCodes(string file, string check)
{
IParser parser = new ZXingParser();
var image = Resources.Load<Texture2D>(file);
ParserResult result = parser.Decode(image.GetPixels32(), image.width, image.height);
StringAssert.Contains(check, result.Value.ToLowerInvariant());
}
#endregion
#region Test Samples
static object[] ImageSamples = {
new object[] {"sample_giant_qr", "september" },
new object[] {"sample_screen_blurry_qr", "http" }
};
[Test, TestCaseSource("ImageSamples")]
public void TestSamples(string file, string check)
{
IParser parser = new ZXingParser();
var image = Resources.Load<Texture2D>(file);
ParserResult result = parser.Decode(image.GetPixels32(), image.width, image.height);
StringAssert.Contains(check, result.Value.ToLowerInvariant());
}
#endregion
}