Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / ATL

SppMk - a unit testing and GNU make support add-in for Visual Studio 6.0

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
11 Jul 200210 min read 155.1K   1.1K   51  
A DevStudio add-in described provides two interesting IDE integration features: adding a new tab to VC WorkspaceView window and running an arbitrary process under IDE with output sent to "Build" tab of VC Output window.
#include "stdafx.h"
#include "DSUtils.h"
#include "Config.h"
#include "MkUtils.h"

MkUtils::MkUtils(AApplication spApp): m_spApp(spApp)
{
}

_bstr_t MkUtils::GetProjectMakefile(const _bstr_t &sProject)
{
    LOG(Logger::cDebug, "MkUtils::GetProjectMakefile(%S){", static_cast<WCHAR*>(sProject));
    TEST_BOOL(m_spApp);
    _bstr_t ret = DSUtils(m_spApp).GetProjectDir(sProject) + "\\Makefile";
    LOG(Logger::cDebug, "MkUtils::GetProjectMakefile()}, ret = '%S'", static_cast<WCHAR*>(ret));
    return ret;
}

bool MkUtils::IsProjectMakeable(const _bstr_t &sProject)
{
	LOG(Logger::cDebug, "MkUtils::IsProjectMakeable(%S){", static_cast<WCHAR*>(sProject));
	_bstr_t sMakefile = GetProjectMakefile(sProject);
	FILE *fp = _wfopen(sMakefile, L"r");
	bool ret = NULL != fp;
	if(NULL != fp)
		fclose(fp);
	LOG(Logger::cDebug, "MkUtils::IsProjectMakeable()}, ret = %d", ret);
	return ret;
}

bool MkUtils::IsProjectTestable(const _bstr_t &sProject)
{
    LOG(Logger::cDebug, "MkUtils::IsProjectTestable(%S){", static_cast<WCHAR*>(sProject));
    _bstr_t sTestMakefile = DSUtils(m_spApp).GetProjectDir(sProject);
    sTestMakefile += "\\UnitTest\\Makefile";
	FILE *fp = _wfopen(sTestMakefile, L"r");
	bool ret = NULL != fp;
	if(NULL != fp)
		fclose(fp);
    LOG(Logger::cDebug, "MkUtils::IsProjectTestable(){, ret = %d", ret);
    return ret;
}

bool MkUtils::IsProjectUTest(const _bstr_t &sProject)
{
    LOG(Logger::cDebug, "MkUtils::IsProjectUTest(%S){", static_cast<WCHAR*>(sProject));
    const WCHAR szSuffix[] = L"_UTest";
    WCHAR *p = wcsstr(static_cast<WCHAR*>(sProject), szSuffix);
    bool ret = NULL != p && L'\0' == *(p + wcslen(szSuffix));
    LOG(Logger::cDebug, "MkUtils::IsProjectUTest()}, ret = %d", ret);
    return ret;
}

_bstr_t MkUtils::CreateMakeCommand(SupportedCommands::CmdId Id)
{
	LOG(Logger::cDebug, "MkUtils::CreateMakeCommand(%d){", Id);
    TEST_BOOL(m_spApp);
    _bstr_t sMake("make");
    if(SupportedCommands::GetInstance().GetCmdInfo(Id).bMake)
	{
		static Config cfg;
		cfg.Load();

		if(cfg.GetCmdMakeOpts(Id).bMasterToDswName)
			sMake += _bstr_t(" MASTER_PROJECT=") + DSUtils(m_spApp).GetDswName();
		if(DSUtils(m_spApp).IsDebug())
			sMake += " DEBUG=1";
		sMake += _bstr_t(" ") + cfg.GetGeneralMakeOpts();
		sMake += _bstr_t(" ") + cfg.GetCmdMakeOpts(Id).sMakeOpts;
	}
	else
	{
        sMake = "echo Unknown command ";
        char buf[20];
		sMake += itoa(Id, buf, 10);
	}
    LOG(Logger::cDebug, "MkUtils::CreateMakeCommand()}, ret = '%S'", static_cast<WCHAR*>(sMake));
    return sMake;
}

_bstr_t MkUtils::AddPathToCmd(const _bstr_t &sMakeCommand, const _bstr_t &sPath)
{
    LOG(Logger::cDebug, "MkUtils::AddPathToCmd(%S){", static_cast<WCHAR*>(sMakeCommand));
    WCHAR *p = wcschr(static_cast<WCHAR*>(sMakeCommand), L' ');
    TEST_BOOL(NULL != p);
    _bstr_t ret = _bstr_t(::SysAllocStringLen(sMakeCommand, p-static_cast<WCHAR*>(sMakeCommand)), false);
    ret += " -C \"";
	ret += sPath;
	ret += "\" ";
    ret += p;
    LOG(Logger::cDebug, "MkUtils::AddPathToCmd()}, ret = %S", static_cast<WCHAR*>(ret));
    return ret;
}

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
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions