本文整理汇总了C++中auto_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ auto_ptr类的具体用法?C++ auto_ptr怎么用?C++ auto_ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了auto_ptr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1:
void
FileOperationMetaTest::testFileOperationSubNone(
auto_ptr<FileOperationInterface> & oper, const fs::path & fileMeta,
const fs::path & fileEntity,
const string & tapeName)
{
string tape;
char buffer[1024] = "hello,world!\n";
char bufferRead[sizeof(buffer)];
size_t size;
struct stat stat;
errno = 0;
CPPUNIT_ASSERT( false == oper->GetStat(stat) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Read(0,bufferRead,sizeof(bufferRead),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
errno = 0;
CPPUNIT_ASSERT( false == oper->Write(0,buffer,sizeof(buffer),size) );
CPPUNIT_ASSERT_ERRNO_( EBADF == errno);
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
errno = 0;
CPPUNIT_ASSERT( false == oper->OpenFile(O_RDWR) );
CPPUNIT_ASSERT_ERRNO_( ENOENT == errno);
CPPUNIT_ASSERT_MESSAGE( fileEntity.file_string(),
true == oper->CreateFile(O_RDWR,0644,false) );
CPPUNIT_ASSERT( fs::exists(fileMeta) );
CPPUNIT_ASSERT( fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->Delete() );
CPPUNIT_ASSERT( ! fs::exists(fileMeta) );
CPPUNIT_ASSERT( ! fs::exists(fileEntity) );
CPPUNIT_ASSERT( true == oper->GetTape(tape) );
CPPUNIT_ASSERT( tape == tapeName );
}
开发者ID:BDT-GER,项目名称:SWIFT-TLC,代码行数:38,代码来源:FileOperationMetaTest.cpp
示例2:
/// Adds a suite to this suite. Tests in added suites will be executed
/// when run() of the top-level suite is called.
///
/// \param suite %Test suite to add.
///
void
Suite::add(auto_ptr<Suite> suite)
{
_suites.push_back(suite.release());
}
开发者ID:1050676515,项目名称:zpublic,代码行数:10,代码来源:suite.cpp
示例3: auto_ptr
auto_ptr(auto_ptr<U>& rhs) : pointee(rhs.release())
{
NULL;
}
开发者ID:chengguixing,项目名称:iArt,代码行数:4,代码来源:main.cpp
示例4: insert
void InputWidgetProxyCollection::insert(
const string& key,
auto_ptr<IInputWidgetProxy> proxy)
{
m_proxies[key] = proxy.release();
}
开发者ID:boberfly,项目名称:gafferDependencies,代码行数:6,代码来源:inputwidgetproxies.cpp
示例5: run_broker
namespace broker {
auto_ptr<QpiddOptions> options;
// Broker real entry; various system-invoked entrypoints call here.
int run_broker(int argc, char *argv[], bool hidden)
{
try
{
BootstrapOptions bootOptions(argv[0]);
string defaultPath (bootOptions.module.loadDir);
// Parse only the common, load, and log options to see which
// modules need to be loaded. Once the modules are loaded,
// the command line will be re-parsed with all of the
// module-supplied options.
try {
bootOptions.parse (argc, argv, bootOptions.common.config, true);
if (hidden)
bootOptions.log.sinkOptions->detached();
qpid::log::Logger::instance().configure(bootOptions.log);
} catch (const std::exception& e) {
// Couldn't configure logging so write the message direct to stderr.
cerr << "Unexpected error: " << e.what() << endl;
return 1;
}
for (vector<string>::iterator iter = bootOptions.module.load.begin();
iter != bootOptions.module.load.end();
iter++)
qpid::tryShlib (iter->data(), false);
if (!bootOptions.module.noLoad) {
bool isDefault = defaultPath == bootOptions.module.loadDir;
qpid::loadModuleDir (bootOptions.module.loadDir, isDefault);
}
// Parse options
options.reset(new QpiddOptions(argv[0]));
options->parse(argc, argv, options->common.config);
// Options that just print information.
if (options->common.help || options->common.version) {
if (options->common.version)
cout << "qpidd (" << qpid::product << ") version "
<< qpid::version << endl;
else if (options->common.help)
options->usage();
return 0;
}
// Everything else is driven by the platform-specific broker
// logic.
QpiddBroker broker;
return broker.execute(options.get());
}
catch(const exception& e) {
QPID_LOG(critical, "Unexpected error: " << e.what());
}
return 1;
}
}}
开发者ID:cajus,项目名称:qpid-cpp-debian,代码行数:61,代码来源:qpidd.cpp
示例6: AutoDetectSNPBlockSize
namespace IBS
{
// using namespace
using namespace std;
using namespace CoreArray;
using namespace CoreArray::Vectorization;
using namespace GWAS;
/// Packed size
static const long _SIZE_ = 256*256;
/// IBS
/// The number of IBS 0 in the packed genotype
UInt8 IBS0_Num_SNP[_SIZE_];
/// The number of IBS 1 in the packed genotype
UInt8 IBS1_Num_SNP[_SIZE_];
/// The number of IBS 2 in the packed genotype
UInt8 IBS2_Num_SNP[_SIZE_];
/// Genetic Distance
/// The distance in the packed genotype
UInt8 Gen_Dist_SNP[_SIZE_];
/// The flag of use of allele frequencies
UInt8 Gen_Both_Valid[_SIZE_];
/// KING robust estimator
/// The square value of genotype difference, (X_m^{(i)} - X_m^{(j)})^2
UInt8 Gen_KING_SqDiff[_SIZE_];
/// N1_Aa requiring both genotypes are available
UInt8 Gen_KING_N1_Aa[_SIZE_];
/// N2_Aa requiring both genotypes are available
UInt8 Gen_KING_N2_Aa[_SIZE_];
/// the number of valid loci
UInt8 Gen_KING_Num_Loci[_SIZE_];
/// The packed genotype buffer
auto_ptr<UInt8> GenoPacked;
/// The allele frequencies
auto_ptr<double> GenoAlleleFreq;
/// Thread variables
const int N_MAX_THREAD = 256;
// PLINK -- IBS
IdMatTriD PLINKIBS_Thread_MatIdx[N_MAX_THREAD];
Int64 PLINKIBS_Thread_MatCnt[N_MAX_THREAD];
// IBS, KING IBD, Individual Similarity
IdMatTri IBS_Thread_MatIdx[N_MAX_THREAD];
Int64 IBS_Thread_MatCnt[N_MAX_THREAD];
/// The pointer to the variable 'PublicIBS' in the function "DoIBSCalculate"
/// The structure of IBS states
struct TIBS_Flag
{
UInt32 IBS0; //< the number of loci sharing no allele
UInt32 IBS1; //< the number of loci sharing only one allele
UInt32 IBS2; //< the number of loci sharing two alleles
TIBS_Flag() { IBS0 = IBS1 = IBS2 = 0; }
};
/// The pointer to the variable 'PublicKING' in the function "DoKINGCalculate"
/// The structure of KING IBD estimator
struct TKINGHomoFlag
{
UInt32 IBS0; //< the number of loci sharing no allele
UInt32 SumSq; //< \sum_m (X_m^{(i)} - X_m^{(j)})^2
double SumAFreq; //< \sum_m p_m (1 - p_m)
double SumAFreq2; //< \sum_m p_m^2 (1 - p_m)^2
TKINGHomoFlag() { IBS0 = SumSq = 0; SumAFreq = SumAFreq2 = 0; }
};
struct TKINGRobustFlag
{
UInt32 IBS0; //< the number of loci sharing no allele
UInt32 nLoci; //< the total number of loci
UInt32 SumSq; //< \sum_m (X_m^{(i)} - X_m^{(j)})^2
UInt32 N1_Aa; //< the number of hetet loci for the first individual
UInt32 N2_Aa; //< the number of hetet loci for the second individual
TKINGRobustFlag() { IBS0 = nLoci = SumSq = N1_Aa = N2_Aa = 0; }
};
/// The pointer to the variable 'PublicDist' in the function "DoDistCalculate"
/// The structure of genetic distance
struct TDissflag
{
Int64 SumGeno;
double SumAFreq;
TDissflag() { SumGeno = 0; SumAFreq = 0; }
};
// TInit object
//.........这里部分代码省略.........
开发者ID:PumpkinL,项目名称:SNPRelate,代码行数:101,代码来源:genIBS.cpp
示例7: setTile
void SVGPaintServerPattern::setTile(auto_ptr<ImageBuffer> tile)
{
m_tile.set(tile.release());
}
开发者ID:Gin-Rye,项目名称:duibrowser,代码行数:4,代码来源:BCSVGPaintServerPatternWK.cpp
示例8: NewRequest
/**
* Check that we send RDM messages correctly.
*/
void RobeWidgetTest::testSendRDMRequest() {
// request
const RDMRequest *rdm_request = NewRequest(DESTINATION);
unsigned int expected_request_frame_size;
uint8_t *expected_request_frame = PackRDMRequest(
rdm_request,
&expected_request_frame_size);
// response
auto_ptr<const RDMResponse> response(
GetResponseFromData(rdm_request, TEST_RDM_DATA, sizeof(TEST_RDM_DATA)));
unsigned int response_size;
uint8_t *response_frame = PackRDMResponse(response.get(), &response_size);
// add the expected response, send and verify
m_endpoint->AddExpectedRobeDataAndReturn(
BaseRobeWidget::RDM_REQUEST,
expected_request_frame,
expected_request_frame_size,
BaseRobeWidget::RDM_RESPONSE,
response_frame,
response_size);
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this, &RobeWidgetTest::ValidateResponse));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
delete[] response_frame;
// now check broadcast messages
// request
rdm_request = NewRequest(BCAST_DESTINATION);
uint8_t *expected_bcast_request_frame = PackRDMRequest(
rdm_request,
&expected_request_frame_size);
// add the expected response, send and verify
m_endpoint->AddExpectedRobeMessage(
BaseRobeWidget::RDM_REQUEST,
expected_bcast_request_frame,
expected_request_frame_size,
ola::NewSingleCallback(this, &RobeWidgetTest::Terminate));
vector<string> packets;
// This is a bit confusing, the ValidateStatus is invoked immediately, but
// we still need to call m_ss.Run() to ensure the correct packet was sent.
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this,
&RobeWidgetTest::ValidateStatus,
ola::rdm::RDM_WAS_BROADCAST,
packets));
CPPUNIT_ASSERT_EQUAL(ola::rdm::RDM_WAS_BROADCAST, m_received_code);
m_ss.Run();
m_endpoint->Verify();
// cleanup time
delete[] expected_bcast_request_frame;
}
开发者ID:Siliconsoul,项目名称:ola,代码行数:65,代码来源:RobeWidgetTest.cpp
示例9: register_factory
void CameraFactoryRegistrar::register_factory(auto_ptr<FactoryType> factory)
{
const string model = factory->get_model();
impl->m_registrar.insert(model, factory);
}
开发者ID:Rapternmn,项目名称:appleseed,代码行数:5,代码来源:camerafactoryregistrar.cpp
示例10: init
Status WhereMatchExpression::init( const StringData& ns,
const StringData& theCode,
const BSONObj& scope ) {
if ( ns.size() == 0 )
return Status( ErrorCodes::BadValue, "ns for $where cannot be empty" );
if ( theCode.size() == 0 )
return Status( ErrorCodes::BadValue, "code for $where cannot be empty" );
_ns = ns.toString();
_code = theCode.toString();
_userScope = scope.getOwned();
NamespaceString nswrapper( _ns );
_scope = globalScriptEngine->getPooledScope( nswrapper.db().toString(), "where" );
_func = _scope->createFunction( _code.c_str() );
if ( !_func )
return Status( ErrorCodes::BadValue, "$where compile error" );
return Status::OK();
}
开发者ID:328500920,项目名称:mongo,代码行数:23,代码来源:expression_where.cpp
示例11: testErrorConditions
/*
* Check some of the error conditions
*/
void ArduinoWidgetTest::testErrorConditions() {
vector<string> packets;
uint8_t ERROR_CODES[] = {2, 3, 4, 5};
// test each of the error codes.
for (unsigned int i = 0; i < sizeof(ERROR_CODES); ++i) {
// request
const RDMRequest *request = NewRequest(DESTINATION);
unsigned int expected_request_frame_size;
uint8_t *expected_request_frame = PackRDMRequest(
request,
&expected_request_frame_size);
// expected response
unsigned int response_size;
uint8_t *response_frame = PackRDMError(
ERROR_CODES[i],
&response_size);
m_endpoint->AddExpectedDataAndReturn(
expected_request_frame,
expected_request_frame_size,
response_frame,
response_size);
m_arduino->SendRDMRequest(
request,
ola::NewSingleCallback(this,
&ArduinoWidgetTest::ValidateStatus,
ola::rdm::RDM_FAILED_TO_SEND,
packets));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
delete[] response_frame;
}
}
开发者ID:Jazeido,项目名称:ola,代码行数:40,代码来源:ArduinoWidgetTest.cpp
示例12: testUnknownDevice
/*
* Check that discovery fails for an unknown device.
*/
void RobeWidgetDetectorTest::testUnknownDevice() {
uint8_t info_data[] = {1, 2, 3, 0, 0};
uint8_t uid_data[] = {0x52, 0x53, 3, 0, 0, 10};
m_endpoint->AddExpectedRobeDataAndReturn(
INFO_REQUEST_LABEL,
NULL,
0,
INFO_RESPONSE_LABEL,
info_data,
sizeof(info_data));
m_endpoint->AddExpectedRobeDataAndReturn(
UID_REQUEST_LABEL,
NULL,
0,
UID_RESPONSE_LABEL,
uid_data,
sizeof(uid_data));
m_detector->Discover(&m_descriptor);
m_ss.Run();
OLA_ASSERT_FALSE(m_found_widget);
OLA_ASSERT(m_failed_widget);
}
开发者ID:Jazeido,项目名称:ola,代码行数:27,代码来源:RobeWidgetDetectorTest.cpp
示例13: sigHandler
void sigHandler( int sigNum ) {
//Log a message that we caught a signal
try {
Logger::info() << "Caught signal " << sigNum << ", shutting down" << endl;
} catch(...) {
cerr << "Caught signal " << sigNum << ", shutting down" << endl;
}
//Kill any sub-threads we have going right now
for( int i = 0; i < activeThreads.size(); i++ ) {
if( pthread_cancel(activeThreads[i]) != 0 ) {
cerr << "Could not pthread_cancel thread " << activeThreads[i] << endl;
}
}
//Delete the primary listening socket
server.release();
//Shutdown the logging mechanism
Logger::shutdown();
//Exit the program
exit( 0 );
}
开发者ID:cyleriggs,项目名称:faketelnetd,代码行数:24,代码来源:main.cpp
示例14: matches
bool WhereMatchExpression::matches(const MatchableDocument* doc, MatchDetails* details) const {
verify(_func);
BSONObj obj = doc->toBSON();
if (!_userScope.isEmpty()) {
_scope->init(&_userScope);
}
_scope->setObject("obj", const_cast<BSONObj&>(obj));
_scope->setBoolean("fullObject", true); // this is a hack b/c fullObject used to be relevant
int err = _scope->invoke(_func, 0, &obj, 1000 * 60, false);
if (err == -3) { // INVOKE_ERROR
stringstream ss;
ss << "error on invocation of $where function:\n" << _scope->getError();
uassert(16812, ss.str(), false);
} else if (err != 0) { // ! INVOKE_SUCCESS
uassert(16813, "unknown error in invocation of $where function", false);
}
return _scope->getBoolean("__returnValue") != 0;
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:22,代码来源:expression_where.cpp
示例15: testErrorConditions
/*
* Check some of the error conditions
*/
void DmxterWidgetTest::testErrorConditions() {
uint8_t RDM_REQUEST_LABEL = 0x80;
UID source(1, 2);
UID destination(3, 4);
UID new_source(0x5253, 0x12345678);
vector<string> packets;
const RDMRequest *request = NewRequest(source, destination, NULL, 0);
unsigned int size = request->Size();
uint8_t *expected_packet = new uint8_t[size + 1];
expected_packet[0] = 0xcc;
CPPUNIT_ASSERT(request->PackWithControllerParams(
expected_packet + 1,
&size,
new_source,
0,
1));
// to small to be valid
uint8_t return_packet[] = {0x00};
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_REQUEST_LABEL,
expected_packet,
size + 1,
RDM_REQUEST_LABEL,
return_packet,
sizeof(return_packet));
m_widget->SendRDMRequest(
request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_INVALID_RESPONSE,
packets));
m_ss.Run();
m_endpoint->Verify();
// check mismatched version
request = NewRequest(source, destination, NULL, 0);
CPPUNIT_ASSERT(request->PackWithControllerParams(
expected_packet + 1,
&size,
new_source,
1, // increment transaction #
1));
// non-0 version
uint8_t return_packet2[] = {0x01, 0x11, 0xcc};
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_REQUEST_LABEL,
expected_packet,
size + 1,
RDM_REQUEST_LABEL,
return_packet2,
sizeof(return_packet2));
m_widget->SendRDMRequest(
request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_INVALID_RESPONSE,
packets));
delete[] expected_packet;
m_ss.Run();
m_endpoint->Verify();
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:75,代码来源:DmxterWidgetTest.cpp
示例16: testSendRDMDUB
/**
* Check that we send RDM discovery messages correctly.
*/
void DmxterWidgetTest::testSendRDMDUB() {
uint8_t RDM_DUB_LABEL = 0x83;
const UID source(0x5253, 0x12345678);
const UID destination = UID::AllDevices();
static const uint8_t REQUEST_DATA[] = {
0x7a, 0x70, 0, 0, 0, 0,
0x7a, 0x70, 0xff, 0xff, 0xff, 0xff
};
// request
const RDMRequest *rdm_request = new ola::rdm::RDMDiscoveryRequest(
source,
destination,
0, // transaction #
1, // port id
0, // message count
0, // sub device
ola::rdm::PID_DISC_UNIQUE_BRANCH, // param id
REQUEST_DATA,
sizeof(REQUEST_DATA));
unsigned int request_size = rdm_request->Size();
uint8_t *expected_request_frame = new uint8_t[request_size + 1];
expected_request_frame[0] = 0xcc;
CPPUNIT_ASSERT(rdm_request->Pack(expected_request_frame + 1, &request_size));
// a 4 byte response means a timeout
static const uint8_t TIMEOUT_RESPONSE[] = {0, 17};
// add the expected response, send and verify
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_DUB_LABEL,
expected_request_frame,
request_size + 1,
RDM_DUB_LABEL,
TIMEOUT_RESPONSE,
sizeof(TIMEOUT_RESPONSE));
vector<string> packets;
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_TIMEOUT,
packets));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
// now try a dub response that returns something
rdm_request = new ola::rdm::RDMDiscoveryRequest(
source,
destination,
1, // transaction #
1, // port id
0, // message count
0, // sub device
ola::rdm::PID_DISC_UNIQUE_BRANCH, // param id
REQUEST_DATA,
sizeof(REQUEST_DATA));
request_size = rdm_request->Size();
expected_request_frame = new uint8_t[request_size + 1];
expected_request_frame[0] = 0xcc;
CPPUNIT_ASSERT(rdm_request->Pack(expected_request_frame + 1, &request_size));
// something that looks like a DUB response
static const uint8_t FAKE_RESPONSE[] = {0x00, 19, 0xfe, 0xfe, 0xaa, 0xaa};
// add the expected response, send and verify
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_DUB_LABEL,
expected_request_frame,
request_size + 1,
RDM_DUB_LABEL,
FAKE_RESPONSE,
sizeof(FAKE_RESPONSE));
packets.push_back(
string(reinterpret_cast<const char*>(&FAKE_RESPONSE[2]),
sizeof(FAKE_RESPONSE) - 2));
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_DUB_RESPONSE,
packets));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:97,代码来源:DmxterWidgetTest.cpp
示例17: Receive
/**
* Receive data and terminate if the stream is bad.
*/
void TCPTransportTest::Receive() {
m_stream_ok = m_transport->Receive();
if (!m_stream_ok)
m_ss->Terminate();
}
开发者ID:Jazeido,项目名称:ola,代码行数:8,代码来源:TCPTransportTest.cpp
示例18: tearDown
void TCPTransportTest::tearDown() {
// Close the loopback descriptor and drain the ss
m_loopback.Close();
m_ss->RunOnce(0, 0);
}
开发者ID:Jazeido,项目名称:ola,代码行数:5,代码来源:TCPTransportTest.cpp
示例19: testSendRDMDUB
/**
* Check that we send RDM discovery messages correctly.
*/
void DmxterWidgetTest::testSendRDMDUB() {
uint8_t RDM_DUB_LABEL = 0x83;
const UID source(0x4744, 0x12345678);
const UID destination = UID::AllDevices();
static const uint8_t REQUEST_DATA[] = {
0x7a, 0x70, 0, 0, 0, 0,
0x7a, 0x70, 0xff, 0xff, 0xff, 0xff
};
// request
RDMRequest *rdm_request = new ola::rdm::RDMDiscoveryRequest(
source,
destination,
0, // transaction #
1, // port id
0, // sub device
ola::rdm::PID_DISC_UNIQUE_BRANCH, // param id
REQUEST_DATA,
sizeof(REQUEST_DATA));
unsigned int request_size = RDMCommandSerializer::RequiredSize(*rdm_request);
uint8_t *expected_request_frame = new uint8_t[request_size + 1];
expected_request_frame[0] = 0xcc;
OLA_ASSERT(RDMCommandSerializer::Pack(*rdm_request,
expected_request_frame + 1,
&request_size));
// a 4 byte response means a timeout
static const uint8_t TIMEOUT_RESPONSE[] = {0, 17};
// add the expected response, send and verify
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_DUB_LABEL,
expected_request_frame,
request_size + 1,
RDM_DUB_LABEL,
TIMEOUT_RESPONSE,
sizeof(TIMEOUT_RESPONSE));
RDMFrames frames;
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_TIMEOUT,
frames));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
// now try a dub response that returns something
rdm_request = new ola::rdm::RDMDiscoveryRequest(
source,
destination,
1, // transaction #
1, // port id
0, // sub device
ola::rdm::PID_DISC_UNIQUE_BRANCH, // param id
REQUEST_DATA,
sizeof(REQUEST_DATA));
request_size = RDMCommandSerializer::RequiredSize(*rdm_request);
expected_request_frame = new uint8_t[request_size + 1];
expected_request_frame[0] = 0xcc;
OLA_ASSERT(RDMCommandSerializer::Pack(*rdm_request,
expected_request_frame + 1,
&request_size));
// something that looks like a DUB response
static const uint8_t FAKE_RESPONSE[] = {0x00, 19, 0xfe, 0xfe, 0xaa, 0xaa};
// add the expected response, send and verify
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_DUB_LABEL,
expected_request_frame,
request_size + 1,
RDM_DUB_LABEL,
FAKE_RESPONSE,
sizeof(FAKE_RESPONSE));
frames.push_back(RDMFrame(&FAKE_RESPONSE[2], arraysize(FAKE_RESPONSE) - 2));
m_widget->SendRDMRequest(
rdm_request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_DUB_RESPONSE,
frames));
m_ss.Run();
m_endpoint->Verify();
delete[] expected_request_frame;
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:97,代码来源:DmxterWidgetTest.cpp
示例20: testSendRDMRequest
/**
* Check that we send messages correctly.
*/
void DmxterWidgetTest::testSendRDMRequest() {
uint8_t RDM_REQUEST_LABEL = 0x80;
uint8_t RDM_BROADCAST_REQUEST_LABEL = 0x81;
UID source(0x4744, 0x12345678);
UID destination(3, 4);
UID bcast_destination(3, 0xffffffff);
RDMRequest *request = NewRequest(source, destination, NULL, 0);
unsigned int size = RDMCommandSerializer::RequiredSize(*request);
uint8_t *expected_packet = new uint8_t[size + 1];
expected_packet[0] = 0xcc;
OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size));
uint8_t return_packet[] = {
0x00, 14, // response code 'ok'
0xcc,
1, 28, // sub code & length
0x47, 0x44, 0x12, 0x34, 0x56, 0x78, // dst uid
0, 3, 0, 0, 0, 4, // src uid
0, 1, 0, 0, 10, // transaction, port id, msg count & sub device
0x21, 0x1, 0x28, 4, // command, param id, param data length
0x5a, 0x5a, 0x5a, 0x5a, // param data
0x04, 0x50 // checksum
};
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_REQUEST_LABEL,
expected_packet,
size + 1,
RDM_REQUEST_LABEL,
return_packet,
sizeof(return_packet));
m_widget->SendRDMRequest(
request,
ola::NewSingleCallback(this, &DmxterWidgetTest::ValidateResponse));
m_ss.Run();
m_endpoint->Verify();
// now check broadcast
request = NewRequest(source, bcast_destination, NULL, 0);
request->SetTransactionNumber(1);
OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size));
m_endpoint->AddExpectedUsbProDataAndReturn(
RDM_BROADCAST_REQUEST_LABEL,
expected_packet,
size + 1,
RDM_BROADCAST_REQUEST_LABEL,
static_cast<uint8_t*>(NULL),
0);
RDMFrames frames;
m_widget->SendRDMRequest(
request,
ola::NewSingleCallback(this,
&DmxterWidgetTest::ValidateStatus,
ola::rdm::RDM_WAS_BROADCAST,
frames));
delete[] expected_packet;
m_ss.Run();
m_endpoint->Verify();
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:68,代码来源:DmxterWidgetTest.cpp
注:本文中的auto_ptr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论