blob: cefc2271484f47b9b96354f061b80d047fd1ed60 (
plain)
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
|
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tango.Protobuf;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Google.Protobuf;
using Tango.PMR.Jobs;
using Tango.PMR.Common;
using Tango.PMR;
using Tango.Logging;
using Newtonsoft.Json;
namespace Tango.UnitTesting
{
[TestClass]
[TestCategory("Protobuf")]
public class Protobuf_TST
{
/// <summary>
/// Compiles all the whole PMR using all available compilers.
/// </summary>
[TestMethod]
public void Compile_All_PMR()
{
var console = Helper.InitializeLogging(true);
String pmrFolder = Helper.GetPMRPath();
List<String> tempFolders = new List<string>();
foreach (var compiler in CompilerFactory.GetAvailableCompilers())
{
CompilerFolderResult result = compiler.CompileFolder(pmrFolder);
String tmpFolder = Helper.GetTempFolderPathAppend(compiler.Language.ToString());
result.Save(tmpFolder);
tempFolders.Add(tmpFolder);
}
Helper.ShowInExplorer(Directory.GetParent(tempFolders.First()).FullName);
console.WaitForConsoleExit().Wait();
foreach (var folder in tempFolders)
{
Helper.TryDeleteFolder(folder);
}
}
/// <summary>
/// Writes and reads a proto message then compares.
/// </summary>
[TestMethod]
public void Read_Write_Message()
{
var console = Helper.InitializeLogging(true);
TangoMessage<Job> container = MessageFactory.CreateContainer<Job>();
container.Message.Name = "Test Job";
container.Message.Segments.Add(new Segment()
{
Color = new RGB() { R = 1, G = 2, B = 3 },
Length = 10,
Name = "Segment 1"
});
container.Message.Segments.Add(new Segment()
{
Color = new RGB() { R = 10, G = 20, B = 30 },
Length = 100,
Name = "Segment 2"
});
LogManager.Log("Write Message:" + Environment.NewLine + JsonConvert.SerializeObject(container.Message, Formatting.Indented));
var bytes = container.ToBytes();
var parsed = MessageFactory.ParseContainer<Job>(bytes);
LogManager.Log("Read Message:" + Environment.NewLine + JsonConvert.SerializeObject(parsed.Message, Formatting.Indented));
Assert.AreEqual(container.Message, parsed.Message);
LogManager.Log("Test Passed!");
console.WaitForConsoleExit().Wait();
}
}
}
|