Click here to Skip to main content
15,896,153 members
Articles / Programming Languages / C#

TILO - An Automated Unit-Testing Tool for C and C++

,
Rate me:
Please Sign up or sign in to vote.
4.57/5 (10 votes)
27 Aug 20056 min read 47.9K   936   45  
Tilo is a program / tool designed to help developers in creating and running unit tests. Unit tests will have to be coded, not written, and will be executed automatically by the tool.
using System;
using TestBusiness;

namespace ProjectLoader
{
	/// <summary>
	/// Summary description for Parser.
	/// </summary>
	public class Parser
	{
		/// <summary>
		/// Constructor
		/// </summary>
		public Parser( )
		{
			
		}

		/// <summary>
		/// Parse the testing information string of a module
		/// and creates its hierarchy accordingly.
		/// </summary>
		/// <param name="module">The module for which to create the hierarchy</param>
		/// <param name="info">Module Unit-Tests Information String</param>
		public void CreateModuleHierarchy( TestModule module, string info)
		{
			TestObject parent;

			string[] firstsplit = null;
			string[] secondsplit = null;

			// split the tests (delimited by ";")
			firstsplit = info.Split( ";".ToCharArray());

			// for each test from the splited string vector
			foreach ( string s in firstsplit)
			{
				parent = module;

				// split the string (delimited by ",")
				secondsplit = s.Split( ",".ToCharArray());

				if (secondsplit.Length < 2)
					throw new Exception("Invalid Test Description String!");

				// get the test name
                string strTestName = secondsplit[secondsplit.Length - 1];

                if (module.Contains(strTestName, false))
					throw new Exception("Duplicated Test Name (" + strTestName + ")!");

				// get the function name
				string strTestFunc = secondsplit[secondsplit.Length - 2];

				// for each category
				for ( int i = 0; i < (secondsplit.Length - 2); ++i)
				{
                    TestObject pto = parent.GetIfContains( secondsplit[i], false);
					TestObject mto = module.GetIfContains( secondsplit[i], false);

					// TODO: Commented out by GEC - Octav to review and fix / delete this commend: crashes if there are two categories (eg Assignment and Comparison) and both contain one subcategory named Strings (or some other name)
//					if (mto != pto)
//						throw new Exception("Abnormal scenario (mto != pto). Error code: 1234. Please contact support team!");
					// END: Commented by Gec

					if ( !((pto == null || pto is TestCategory) || (pto is TestModule)))
						throw new Exception("Abnormal scenario. Error code: 1235. Please contact support team!");

					if (pto != null)
						parent = pto;
					else 
					{
						TestObject category = new TestCategory( secondsplit[i]);
						parent.AddChild( category);
						parent = category;
					}
				}

				parent.AddChild( new UnitTest( strTestName, strTestFunc));
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Cyprus Cyprus
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions