|
You need to include header file or files did you include files
|
|
|
|
|
i am using VC++6 with DOM creating and manuplating XML file.
i had created xml tags at run time and given default namespace , created some child nodes like this
<root xmlns="http://...">
<firstchild/>
<secondchild/>
</root>
,now i need to get the child from other part of the project so
I am using selectSingleNode() say like selectSingleNode("//root") but this is returning null so I used setProperty() to add a prefix to the namespace
and called the selectSingleNode("//pre:root") but still it is returning Null
y is it so
thanks in advance
|
|
|
|
|
I'm working with VC++6.0. I have a SDI application. I want to do unit test on some functions, but how do I run it?
Say I have a function
BOOL IsValid (MyType *p);
And the unit test I write for it is:
void TestIsValid()
When I run my application in Debug mode, how can I run "TestIsValid"?
Thank you very much for any help!
|
|
|
|
|
Use the #ifdef and #endif blocks:
BOOL IsValid (MyType *p) {
#ifdef _DEBUG
TestIsValid();
#endif
}
|
|
|
|
|
thank you, walder.
but in my "TestIsValid()", I will call "IsValid()", I'm afraid this will cause an infinite recurrent problem.
the other problem is, "IsValid( )" is called quite a few times in the application, I don't want to run the unit test code all the time.
Is there a way to get something like a shell window, and I just type in "TestIsValid" to get it run?
Thanks!
|
|
|
|
|
deport your unit tests into their own project into the solution, with a reference to the sources to be tested.
|
|
|
|
|
thank you, toxcct.
Can you elaborate on how to do that?
|
|
|
|
|
Sorry, I'm having a difficult time trying to understand what you are doing? It sounds like you have a function TestIsValid() which in turn calls IsValid() which in turn calls TestIsValid() , and so on... Perhaps you could show me some code.
You dont have to use the only the DEBUG definition, you can create your own
#ifdef DEBUG
#ifdef MYFUNC_1
#endif
#endif
|
|
|
|
|
do you know what unit tests are for ?
they are written to verify that management rules are correctly implemented. for this, unit tests can be ran, but they mustn't be included in the main project as their code is only for the development purpose...
|
|
|
|
|
toxcct wrote: for this, unit tests can be ran, but they mustn't be included in the main project as their code is only for the development purpose
That is, of course, unless you are following one of the Agile Design models. In almost all of those paradigms, the unit test cases should accompany the source code, but won't get linked into the final application (generally, you have a separate unit-test project file that has a main.cpp that simply calls all your unit tests and reports the results).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
To be honest I have never heard of them, but I guess they are something similar to the ASSERT() macro, only with more functionality.
|
|
|
|
|
waldermort wrote: To be honest I have never heard of them
You have never heard of unit tests?
waldermort wrote: similar to the ASSERT() macro, only with more functionality.
Not really. Unit tests isolate a module and do a thorough diagnostic on it. That is, a good unit test will test all the public methods of a module to make sure they give the desired results.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: You have never heard of unit tests?
That surprises you?
led mike
|
|
|
|
|
It does surprise me a bit. That is one of the topics that should be required for any computer science/computer engineering curiculum, but I guess some places don't think you need to test your work :-P
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: That is one of the topics that should be required
one of the "many" that aren't.
led mike
|
|
|
|
|
here's the sample code:
<br />
BOOL IsValid(MyType *p)<br />
{<br />
<br />
<br />
.....<br />
}<br />
<br />
void TestIsValid ()<br />
{<br />
MyType a;<br />
BOOL bRet;<br />
<br />
bRet = IsValid (&a);<br />
printf ("IsValid( ) returns %d.\n", bRet);<br />
}<br />
So I don't see I can use what you recommended first as:
<br />
BOOL IsValid (MyType *p)<br />
{<br />
...<br />
#ifdef _DEBUG<br />
TestIsValid();<br />
#endif<br />
}<br />
I hope I made myself clear this time.
|
|
|
|
|
So place it in the other function:
void TestIsValid()
{
MyType a;
BOOL bRet = false;
#ifdef _DEBUG
bRet = IsValid (&a);
printf ("IsValid( ) returns %d.\n", bRet);
#endif
}
|
|
|
|
|
What with ANSI, UNICODE and MBCS there's a lot can go wrong. Usualy I build MBCS only apps, but I am now taking into account that I may one day re-use my code in a UNICODE build. So I am making use of tchar.h .
Now, I have created a function which performs various tasks on a string
int DrawVertText(HDC hdc,LPCTSTR lpString,int nCount,LPRECT lpRect,UINT uFormat)
According to MSDN with a MBCS build, that LPCTSTR Resolves to a "constant string of TCHAR (const TCHAR*)" which in turn resolves to a "constant string of char (const char*)", and for a UNICODE build a "constant string of wchar_t (const wchar_t*)". I later use the string
int iLength = _tcsclen(lpString); In my MBCS build it works, when I switch to UNICODE I get the following error
error C2664: 'wcslen' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
Why has the string not been resolved to wchar_t ? Also, the mouseover popup in MSVS tells me that lpString is an unsigned short* .
|
|
|
|
|
A simple solution to a simple problem. In my stdafx.h I added
#ifdef _UNICODE
#ifndef UNICODE
#define UNICODE
#endif
#endif
Why are there two definitions?
|
|
|
|
|
waldermort wrote: Why are there two definitions?
The simple answer: When you have multiple teams working on adding support for similar features, and they don't communicate well, you end up with overlapping functionality.
This is also part of the reason why there are sections of MFC that deal with return values for errors, others that throw exceptions, and still others that require you to check GetLastError periodically.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
UNICODE is used by the Windows headers to switch between the A and W versions of APIs
_UNICODE is used by the CRT headers to switch between MBCS and Unicode versions of the string functions (this is how _tcsxxx macros work)
You should always define both or neither of those symbols
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I want to add the regsvr32 command as a post-build event in my makefile.How do i do it?
Is it possible to specify post-build events in makefiles?
a small example will be appreciated
|
|
|
|
|
Hello,
I have a program that takes a command line argument and then converts it to a unicode string (with MultiByteToWide) for use in NetLocalGroupEnum (not shown in the program extract below).
The strange thing is that when I have a printf (line 18 below) at the start of the program, it seems to work fine (It prints the converted string).
But when I remove the printf the string conversion is not correct anymore. I must be doing something wrong with 'sizeof' or with the MultiByteToWideChar function.
01 #pragma comment( lib, "netapi32.lib" )
02 #include <stdio.h>
03
04 #include <stdlib.h>
05 //#include <string.h>
06 #include <windows.h>
07 #include <atl\atlbase.h>
08
09 #include <lmcons.h>
10 #include <lmaccess.h>
11 #include <lm.h>
12 #include <sddl.h>
13
14 int main(int argc, char** argv)
15 {
16 char buf[256];
17
18 //printf("Test\n\n");
19
20 if (argc < 2) {
21 printf("Usage:lgenum2 <servername>");
22 exit(EXIT_FAILURE);
23 }
24
25 LPWSTR servername = new WCHAR[sizeof(argv[1])+1];
26
27 MultiByteToWideChar (
28 CP_ACP, // code page
29 0, // performance and mapping flags
30 (char *) argv[1], // address of character string
31 -1, // number of characters in string
32 servername, // address of buffer for new string
33 wcslen(servername) // size of buffer
34 );
35
36 wprintf(L"Multibyte to Widechar:%s\n",servername);
37 printf("-------\n\n");
38 exit(EXIT_SUCCESS);
39 }
Thanks for any help
Francis
|
|
|
|
|
fvandun wrote: LPWSTR servername = new WCHAR[sizeof(argv[1])+1];
26
27 MultiByteToWideChar (
28 CP_ACP, // code page
29 0, // performance and mapping flags
30 (char *) argv[1], // address of character string
31 -1, // number of characters in string
32 servername, // address of buffer for new string
33 wcslen(servername) // size of buffer
34 );
The above should be written as:
size_t wStrSize = strlen(argv[1] + 1);
LPWSTR servername = new WCHAR[wStrSize];
MultiByteToWideChar( CP_ACP,
MB_PRECOMPOSED,
(const char*)argv[1],
-1,
servername,
wStrSize);
That should fix your problem.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks Zac,
I substituted your lines.
But now when I print my MultiByte string with wprintf, it has a lot of garbage characters at the end:
D:\Dev\CPP\Projects>t1 01234567890123456789
Test 01234567890123456789
Multibyte to Widechar:01234567890123456789▄♠n\?2?2???????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????---------------------------------------
Any more suggestions?
Thanks
Francis
|
|
|
|