1 | // Copyright (C) 2000, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
---|
4 | // $Id: osiUnitTest.cpp 1854 2013-01-28 00:02:55Z forrest $ |
---|
5 | |
---|
6 | #include "CoinPragma.hpp" |
---|
7 | |
---|
8 | #include <iostream> |
---|
9 | |
---|
10 | #include "OsiUnitTests.hpp" |
---|
11 | #include "OsiCbcSolverInterface.hpp" |
---|
12 | |
---|
13 | using namespace OsiUnitTest; |
---|
14 | |
---|
15 | //---------------------------------------------------------------- |
---|
16 | // to see parameter list, call unitTest -usage |
---|
17 | //---------------------------------------------------------------- |
---|
18 | |
---|
19 | int main (int argc, const char *argv[]) |
---|
20 | { |
---|
21 | /* |
---|
22 | Start off with various bits of initialisation that don't really belong |
---|
23 | anywhere else. |
---|
24 | |
---|
25 | Synchronise C++ stream i/o with C stdio. This makes debugging |
---|
26 | output a bit more comprehensible. It still suffers from interleave of cout |
---|
27 | (stdout) and cerr (stderr), but -nobuf deals with that. |
---|
28 | */ |
---|
29 | std::ios::sync_with_stdio() ; |
---|
30 | /* |
---|
31 | Suppress an popup window that Windows shows in response to a crash. See |
---|
32 | note at head of file. |
---|
33 | */ |
---|
34 | WindowsErrorPopupBlocker(); |
---|
35 | |
---|
36 | /* |
---|
37 | Process command line parameters. |
---|
38 | */ |
---|
39 | std::map<std::string,std::string> parms; |
---|
40 | if (processParameters(argc,argv,parms) == false) |
---|
41 | return 1; |
---|
42 | |
---|
43 | std::string mpsDir = parms["-mpsDir"] ; |
---|
44 | std::string netlibDir = parms["-netlibDir"] ; |
---|
45 | |
---|
46 | /* |
---|
47 | Test Osi{Row,Col}Cut routines. |
---|
48 | */ |
---|
49 | { |
---|
50 | OsiCbcSolverInterface cbcSi; |
---|
51 | testingMessage( "Testing OsiRowCut with OsiCbcSolverInterface\n" ); |
---|
52 | OSIUNITTEST_CATCH_ERROR(OsiRowCutUnitTest(&cbcSi,mpsDir), {}, cbcSi, "rowcut unittest"); |
---|
53 | } |
---|
54 | { |
---|
55 | OsiCbcSolverInterface cbcSi; |
---|
56 | testingMessage( "Testing OsiColCut with OsiCbcSolverInterface\n" ); |
---|
57 | OSIUNITTEST_CATCH_ERROR(OsiColCutUnitTest(&cbcSi,mpsDir), {}, cbcSi, "colcut unittest"); |
---|
58 | } |
---|
59 | { |
---|
60 | OsiCbcSolverInterface cbcSi; |
---|
61 | testingMessage( "Testing OsiRowCutDebugger with OsiCbcSolverInterface\n" ); |
---|
62 | OSIUNITTEST_CATCH_ERROR(OsiRowCutDebuggerUnitTest(&cbcSi,mpsDir), {}, cbcSi, "rowcut debugger unittest"); |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | Run the OsiCbc class test. This will also call OsiSolverInterfaceCommonUnitTest. |
---|
67 | */ |
---|
68 | testingMessage( "Testing OsiCbcSolverInterface\n" ); |
---|
69 | OSIUNITTEST_CATCH_ERROR(OsiCbcSolverInterfaceUnitTest(mpsDir,netlibDir), {}, "cbc", "osicbc unittest"); |
---|
70 | |
---|
71 | /* |
---|
72 | We have run the specialised unit test. |
---|
73 | Check now to see if we need to run through the Netlib problems. |
---|
74 | */ |
---|
75 | if (parms.find("-testOsiSolverInterface") != parms.end()) |
---|
76 | { |
---|
77 | // Create vector of solver interfaces |
---|
78 | std::vector<OsiSolverInterface*> vecSi(1, new OsiCbcSolverInterface); |
---|
79 | |
---|
80 | testingMessage( "Testing OsiSolverInterface on Netlib problems.\n" ); |
---|
81 | OSIUNITTEST_CATCH_ERROR(OsiSolverInterfaceMpsUnitTest(vecSi,netlibDir), {}, "cbc", "netlib unittest"); |
---|
82 | |
---|
83 | delete vecSi[0]; |
---|
84 | } |
---|
85 | else |
---|
86 | testingMessage( "***Skipped Testing of OsiCbcSolverInterface on Netlib problems, use -testOsiSolverInterface to run them.***\n" ); |
---|
87 | |
---|
88 | /* |
---|
89 | We're done. Report on the results. |
---|
90 | */ |
---|
91 | std::cout.flush(); |
---|
92 | outcomes.print(); |
---|
93 | |
---|
94 | int nerrors; |
---|
95 | int nerrors_expected; |
---|
96 | outcomes.getCountBySeverity(TestOutcome::ERROR, nerrors, nerrors_expected); |
---|
97 | |
---|
98 | if (nerrors > nerrors_expected) |
---|
99 | std::cerr << "Tests completed with " << nerrors - nerrors_expected << " unexpected errors." << std::endl ; |
---|
100 | else |
---|
101 | std::cerr << "All tests completed successfully\n"; |
---|
102 | |
---|
103 | return nerrors - nerrors_expected; |
---|
104 | } |
---|