How to Use Amop in VC6

Source: Internet
Author: User

Amop is an open-source automatic Mock tool (thanks to the original author and we have developed such a useful framework). It is a Mock implemented using a virtual function table, therefore, the original author of Mock that only applies to virtual functions emphasizes that it is only applicable to pure virtual functions. It can be used as long as it is a virtual function ). Compared with similar C ++ Mock tools, the biggest advantage of Amop is that it does not need to implement virtual classes and is completely processed by the Amop framework, which greatly facilitates user use.
Templates are widely used in Amop, while Visual C ++ 6.0 has poor support for templates before the C ++ standard is released, therefore, it is very difficult to use this tool in Visual C ++ 6.0, and Visual C ++ 6.0 has not been released for a long time, is the Amop tool unavailable in Visual C ++ 6.0?
After twists and turns, I finally found a feasible solution.
The Intel C ++ compiler can be integrated into Visual C ++ 6.0, while the Intel C ++ compiler has been available in new versions. Now, some versions have better support for templates, therefore, installing an Intel C ++ compiler can solve the compilation problem. Because Amop uses the virtual function table directly, many features are closely related to compiler implementation, so many problems have also been found during compilation under the Intel C ++ compiler, after some Amop functions are finally removed, the compilation and test are passed. Therefore, the current Amop can be used in Visual C ++ 6.0 under certain restrictions (it is a virtual function, not a Destructor, and does not use a char * Parameter comparison.1. VC6 integrates Intel C ++ 8/9.
1. Install VC6 in English version. Select "select all" during installation to avoid Unicode unsupported.
2. Install Intel C ++. Place lisence in a path without spaces or Chinese characters.
3. Select "do not install italian" during installation ".
4. Click the following menu to open the compiler Settings dialog box.
5 if you select the Intel compiler, it will be compiled using the Intel compiler.2. Configure the Amop Environment
Change the Amop header file and the library file to the $ (LLT_PATH) \ Amop directory. Then, make the following settings in the project:
1. added the compilation parameter:/I "$ (LLT_PATH) \ Amop \ include"
2. Add/libpath: "$ (LLT_PATH) \ Amop \ lib \ VC6 \ Intel9.1" to the Link parameter"
3. Link Amop. lib to the project.
4. The file using the Amop tool contains the MockObject. h file and uses the amop namespace.3. How to Use Amop
3. 1. Define a mock object
Assuming that the interface (class) to be tested is an IInterface, use the following statement to define the mock object.
TMockObject <IInterface> mock;
. Set the function for Mock
Suppose SimpleFunction is a virtual function defined in IInterface.
Mock. Method (& IInterface: SimpleFunction );
If you do not set the function to be Mock, The TNotImplementedException will be thrown when you call this function (IInterface *) mock)-& gt; SimpleFunction.
3. Set the function return value (Will/Wills)
If you need the function ComplexFunction to return the specified value, you can use "Will" to set its return value. (Note: mock sets the behavior of a mock object and generates an expected result for the mock object. All other commands set the behavior of the mock object except for checking whether the input parameter is correct. There is no way to determine the return value of each call. The objects to be tested and Mock must be distinguished .)
If only one returned value is set, use "Will" to set multiple Wills.
Mock. method (& IInterface: ComplexFunction ). will ("Test Result"); sets the return value for each call of the Function Multiple times: sets the number of returned values and the number of calls Will throw an exception.3. 4. Set the function to Throw the specified exception (Throw/Throws)
If you need the SimpleFunctionWithReturn function to throw a SimpleException (22) exception, you can use Throws to set the exception it Throws.3. 5. Set the expected input parameters (Expect CT/Expects) in the function call)
If the input parameter is not a set value, an exception is thrown.
See the following example. The template parameter (<>) is the parameter serial number, starting from 0. Here there are three parameters. Set the expected input parameters for multiple calls each time
The following example sets the expected input parameters for each call three times. Set and test the expected input parameters.

. Set the output parameter of the function to the specified value (Set/Sets)
Use the Set function. The serial number of the output parameter in the angle brackets starts from 0 ). Set the output of each call of a function for multiple calls.3. 7. Check the number of function calls (Count)
Count () can be used to obtain the number of function calls. If it is used to set the Mock function, you can set the number of function calls.
Gets the number of function calls.
Set the number of function calls, and then use Verify to check whether the function runs as scheduled.3. 8. Check the running result (Verify)
See the last use case in section 3.7. Verify must be used in the case to check whether the running process meets the expectation, so as to avoid non-conformity and no error.
3. 9. Clear the Mock setting function (Clear) 3. 10. Set function call redirection (Redirect)
Redirecting to another function in a call is equivalent to Piling ).4. The VC6 compiler appeared before the emergence of the C ++ International Standard
4.1.C ++ standard milestones
Milestones
The complete list of former and proposed target dates is shown in below.
Date Event
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
9/89 USA requested to submit C ++ New Work Item Proposal
4/91 Approved C ++ NP
6/91 First meeting of WG21
12/93 Circulate informal draft within SC22
7/94 Vote to register WD as CD; Mtg #10.
9/94 Complete editorial corrections; provide WD to SC22.
10/94 Begin CD registration ballot.
3/95 Complete CD registration ballot resolutions; Mtg #12.
6/95 Begin CD ballot.
7/96 Complete CD ballot resolution; Mtgs #14‐16
9/96 Begin second CD ballot
7/97 Complete second CD ballot resolution; Mtg #18, 19
9/97 Begin FDIS ballot
4/98 Complete editorial corrections from DIS ballot
Resolution. Send IS to ITTF (with final report ).
9/98 ITTF to publish the International Standard.
4.2.Visual C ++ 6.0 release date
It can be seen from the 98 years:5. troubleshooting of Amop Compilation
1. Compilation fails because the number of bytes of the Destructor type is different from that of the common pointer. After removing the use case for testing the destructor, compile OK.
2. The link fails. Use the compilation option to remove the two TestAmop libraries/nodefaultlib: "LIBCPD. lib "/nodefaultlib:" LIBCD. after lib ", there is still the problem that UnitTest ++ called functions are not implemented. We found that UnitTest ++ and Amop defined compilation options have problems, one MLd and one MDd, compile OK after all are unified into MDd.
3. There are four use cases. However, an exception is thrown during running. It is found that the const char * Parameter comparison considers the parameters to be different, and Amop throws an exception if the parameters are different. An exception is thrown when both char * and char [] are used. Use std: string.
Virtual void SimpleFunctionWithParams (float, std: string,/* const char **/std: string) = 0;
Virtual int SimpleFunctionWithParamsAndReturn (float, std: string,/* const char **/std: string) = 0;
4. Intel9.1 compiler. If # endif is followed by a comment, a compilation error occurs: Change the comment to the next line. For more complete versions with images, see the attachment.

This article is from the "Jelly software technology blog" blog, please be sure to keep this source http://sinojelly.blog.51cto.com/479153/214385

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.