예제 #1
0
        static void Main(string[] args)
        {
#if !LOAD_DLL_BY_METHOD_1
            IntPtr ptrDll   = LoadLibrary(@"calc.so");
            IntPtr procAddr = GetProcAddress(ptrDll, "calc");
            calc = (calcDelegate)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(procAddr, typeof(calcDelegate));
#endif

            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try{
                listener.Bind(new System.Net.IPEndPoint(IPAddress.Parse(HOST), PORT));
                listener.Listen(1);
                int toExit = 0;
                while (toExit == 0)
                {
                    Socket client = listener.Accept();
                    toExit = handleClient(client);
                }
            }
            catch (Exception e) {
                System.Console.WriteLine(e.ToString());
            }

            listener.Close();
            return;
        }
예제 #2
0
        private static void testMethod(string resultsFileDir, StreamWriter resultsFile, calcDelegate testMethod, string TestName, string operation, double num1, double num2, double expectedResult)
        {
            Trace.AutoFlush = true;
            var sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose");

            CalcTraceSource.Switch = sourceSwitch;
            // simple addition test - this is expeced to fail since there is a bug in add logic...
            string traceFilePath = resultsFileDir + "/" + TestName + ".log";
            TextWriterTraceListener textListener = new TextWriterTraceListener(traceFilePath);

            CalcTraceSource.Listeners.Add(textListener);
            double mathResult;
            string output, startTime = null, endTime = null, result;

            try
            {
                //record start time of the test...
                startTime = DateTime.Now.ToString();
                CalcTraceSource.TraceInformation("Starting test at time: {0}", startTime);

                //call the method to be tested and record the result...
                mathResult = testMethod(num1, num2);

                //record end time of the test...
                endTime = DateTime.Now.ToString();

                //write the test result...

                result = mathResult == expectedResult ? "Passed" : "Failed";
                output = String.Format("{0},{1},Tested {2} {3} {4}); Expected {5}; Actual: {6};,,{7},{8},{9}", TestName, result, num1, operation, num2, expectedResult, mathResult, startTime, endTime, traceFilePath);
                Console.WriteLine(output);
                resultsFile.WriteLine(output);
                CalcTraceSource.TraceInformation("Output: " + output);
                CalcTraceSource.TraceInformation("Ending test at time: {0}", endTime);
            }
            catch (Exception e)
            {
                result = "Error";
                output = String.Format("{0},{1},Tested {2} {3} {4}); Expected {5}; Actual: {6};,,{7},{8},{9}", TestName, result, num1, operation, num2, expectedResult, e.Message, startTime, endTime, traceFilePath);
                output = output.Replace("\n", "\t"); // else, newlines from stack trace will mess with csv file...
                output = output.Replace("\n", "\t"); // else, newlines from stack trace will mess with csv file...
                Console.WriteLine(output);
                resultsFile.WriteLine(output);
                CalcTraceSource.TraceEvent(TraceEventType.Error, 2, "Test errored out...Output:\n" + output + "\n");
            }

            CalcTraceSource.Listeners.Remove(textListener);
            CalcTraceSource.Close();
        }