2012-04-19 14:35:52 +08:00
|
|
|
#include "CurlTest.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "curl/curl.h"
|
|
|
|
|
|
|
|
CurlTest::CurlTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create("Curl Test", "Arial", 28);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(label, 0);
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y-50) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(CurlTest::onTouchesEnded, this);
|
|
|
|
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create a label to display the tip string
|
2013-06-20 14:17:10 +08:00
|
|
|
_label = LabelTTF::create("Touch the screen to connect", "Arial", 22);
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setPosition(VisibleRect::center());
|
|
|
|
addChild(_label, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the test code is
|
|
|
|
// http://curl.haxx.se/mail/lib-2009-12/0071.html
|
2013-09-03 18:22:03 +08:00
|
|
|
void CurlTest::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
char buffer[10];
|
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if (curl)
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "google.com");
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
/* always cleanup */
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
if (res == 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString("0 response");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(buffer,"code: %i",res);
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString(buffer);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString("no curl");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurlTest::~CurlTest()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurlTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new CurlTest();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|