PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/WabbitStudio/Tests/SPASMTests/MismatchTests.cpp

#
C++ | 95 lines | 83 code | 10 blank | 2 comment | 0 complexity | 3cd7eba9377183286f8ff11b34132a14 MD5 | raw file
 1#pragma unmanaged
 2
 3#pragma comment(lib, "spasm.lib")
 4#include "..\SPASM\pass_one.h"
 5#include "..\SPASM\pass_two.h"
 6#include "..\SPASM\parser.h"
 7#include "..\SPASM\spasm.h"
 8#include "..\SPASM\errors.h"
 9#include "..\SPASM\storage.h"
10
11#include <stdio.h>
12#include <direct.h>
13//#include <string>
14
15#pragma managed
16
17using namespace System;
18using namespace System::Text;
19using namespace System::Collections::Generic;
20using namespace	Microsoft::VisualStudio::TestTools::UnitTesting;
21
22
23
24using namespace std;
25
26namespace SPASMTestsVS2008
27{
28	[TestClass]
29	public ref class MismatchTests
30	{
31	public: 
32		[TestInitialize]
33		void Init()
34		{
35		}
36
37		[TestCleanup]
38		void Cleanup()
39		{
40		}
41
42		// Run the file, return the error code
43		int RunTest(const char *file_name)
44		{
45			ClearSPASMErrorSessions();
46			char full_filename[256] = "..\\..\\..\\..\\..\\Tests\\SPASMTests\\";
47			strcat_s(full_filename, file_name);
48
49			OutputDebugString(TEXT("Start\n"));
50			output_contents = (unsigned char *) malloc(output_buf_size);
51			init_storage();
52			curr_input_file = _strdup(full_filename);
53			output_filename = "output.bin";
54			mode = MODE_LIST;
55
56			run_assembly();
57
58			mode = 0;
59			free_storage();
60			free(output_contents);
61
62			return (int) GetLastSPASMError();
63		}
64
65		[TestMethod]
66		void Mismatch1()
67		{
68			RunTest("mismatch1.z80");
69			Assert::AreEqual(SPASM_ERR_UNMATCHED_IF, (int) GetLastSPASMError(), "Wrong error code");
70			Assert::AreEqual(1, GetLastSPASMErrorLine(), "Wrong error line");
71		}
72		[TestMethod]
73		void Mismatch2()
74		{
75			RunTest("mismatch2.z80");
76			Assert::AreEqual(SPASM_ERR_UNMATCHED_IF, (int) GetLastSPASMError(), "Wrong error code");
77			Assert::AreEqual(5, GetLastSPASMErrorLine(), "Wrong error line");
78		}
79		[TestMethod]
80		void Mismatch3()
81		{
82			Assert::AreEqual(SPASM_ERR_UNMATCHED_IF, RunTest("mismatch3.z80"));
83		}
84		[TestMethod]
85		void Mismatch4()
86		{
87			Assert::AreEqual(SPASM_ERR_UNMATCHED_IF, RunTest("mismatch4.z80"));
88		}
89		[TestMethod]
90		void Mismatch5()
91		{
92			Assert::AreEqual(SPASM_ERR_SUCCESS, RunTest("mismatch5.z80"));
93		}
94	};
95}