/* ****************************************************************************
*
* parseAttributeValue - 
*/
std::string parseAttributeValue(ConnectionInfo* ciP, ContextAttribute* caP)
{
  Document    document;
  OrionError  oe;

  document.Parse(ciP->payload);

  if (document.HasParseError())
  {
    alarmMgr.badInput(clientIp, "JSON parse error");
    oe.reasonPhrase = ERROR_STRING_PARSERROR;
    oe.details      = "Errors found in incoming JSON buffer";
    ciP->httpStatusCode = SccBadRequest;;
    return oe.render(ciP, "");
  }


  if (!document.IsObject() && !document.IsArray())
  {
    alarmMgr.badInput(clientIp, "JSON parse error");
    oe.fill(SccBadRequest, "Neither JSON Object nor JSON Array for attribute::value");
    ciP->httpStatusCode = SccBadRequest;;

    return oe.render(ciP, "");
  }

  caP->valueType  = (document.IsObject())? orion::ValueTypeObject : orion::ValueTypeVector;
  parseContextAttributeCompoundValueStandAlone(document, caP, caP->valueType);

  return "OK";
}
TYPED_TEST(DocumentMove, MoveAssignment) {
    typedef TypeParam Allocator;
    typedef GenericDocument<UTF8<>, Allocator> Document;
    Allocator allocator;

    Document a(&allocator);
    a.Parse("[\"one\", \"two\", \"three\"]");
    EXPECT_FALSE(a.HasParseError());
    EXPECT_TRUE(a.IsArray());
    EXPECT_EQ(3u, a.Size());
    EXPECT_EQ(&a.GetAllocator(), &allocator);

    // Document b; b = a; // does not compile (!is_copy_assignable)
    Document b;
    b = std::move(a);
    EXPECT_TRUE(a.IsNull());
    EXPECT_TRUE(b.IsArray());
    EXPECT_EQ(3u, b.Size());
    EXPECT_EQ(&a.GetAllocator(), (void*)0);
    EXPECT_EQ(&b.GetAllocator(), &allocator);

    b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}");
    EXPECT_FALSE(b.HasParseError());
    EXPECT_TRUE(b.IsObject());
    EXPECT_EQ(2u, b.MemberCount());

    // Document c; c = a; // does not compile (see static_assert)
    Document c;
    c = std::move(b);
    EXPECT_TRUE(b.IsNull());
    EXPECT_TRUE(c.IsObject());
    EXPECT_EQ(2u, c.MemberCount());
    EXPECT_EQ(&b.GetAllocator(), (void*)0);
    EXPECT_EQ(&c.GetAllocator(), &allocator);
}
示例#3
0
void PiIO::loadPins()
{
  // fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("pins.json");
//http://rapidjson.org/md_doc_stream.html#FileReadStream

  cout << "load pins" << endl;

  FILE* fp = fopen("pins.json", "r"); // non-Windows use "r"
  char readBuffer[65536];
  FileReadStream is(fp, readBuffer, sizeof(readBuffer));
  Document document;
  document.ParseStream(is);
  fclose(fp);

  assert(document.HasMember("pins"));
  assert(document.IsObject());

  const Value& data = document["pins"];
  //const Value& data = document.FindMember("pins");//.value;
  int size = data.Size();
  size = size - 1;
  cout << "Size is " << size << endl;
  for (int i = size; i >= 0; i--){ // Uses SizeType instead of size_t
    int wpi = -1;
    if(data[i].HasMember("wpi")){
      wpi = data[i]["wpi"].GetInt();
    }
    pins[i].startup(data[i]["pin"].GetInt(), data[i]["name"].GetString(), wpi, i);
  }
  cout << getInfoString() << endl;
}
示例#4
0
void RankScene::onGetRankResponse(HttpClient * sender, HttpResponse *response) {
	if (!response) return;

	if (!response->isSucceed()) {
		log("response failed");
		log("error buffer: %s", response->getErrorBuffer());
		return;
	}

	string res = Global::toString(response->getResponseData());
	Document d;
	d.Parse<0>(res.c_str());

	if (d.HasParseError()) {
		CCLOG("GetParseError %s\n", d.GetParseError());
	}

	if (d.IsObject() && d.HasMember("result") && d.HasMember("info")) {
		bool result = d["result"].GetBool();
		if (!result) {
			CCLOG("Failed to login: %s\n", d["info"].GetString());
		}
		else {
			setRankBoard(d["info"].GetString());
		}
	}
}
示例#5
0
TYPED_TEST(DocumentMove, MoveConstructor) {
    typedef TypeParam Allocator;
    typedef GenericDocument<UTF8<>, Allocator> Document;
    Allocator allocator;

    Document a(&allocator);
    a.Parse("[\"one\", \"two\", \"three\"]");
    EXPECT_FALSE(a.HasParseError());
    EXPECT_TRUE(a.IsArray());
    EXPECT_EQ(3u, a.Size());
    EXPECT_EQ(&a.GetAllocator(), &allocator);

    // Document b(a); // does not compile (!is_copy_constructible)
    Document b(std::move(a));
    EXPECT_TRUE(a.IsNull());
    EXPECT_TRUE(b.IsArray());
    EXPECT_EQ(3u, b.Size());
    EXPECT_THROW(a.GetAllocator(), AssertException);
    EXPECT_EQ(&b.GetAllocator(), &allocator);

    b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}");
    EXPECT_FALSE(b.HasParseError());
    EXPECT_TRUE(b.IsObject());
    EXPECT_EQ(2u, b.MemberCount());

    // Document c = a; // does not compile (!is_copy_constructible)
    Document c = std::move(b);
    EXPECT_TRUE(b.IsNull());
    EXPECT_TRUE(c.IsObject());
    EXPECT_EQ(2u, c.MemberCount());
    EXPECT_THROW(b.GetAllocator(), AssertException);
    EXPECT_EQ(&c.GetAllocator(), &allocator);
}
示例#6
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseLength_MemoryPoolAllocator)) {
    for (size_t i = 0; i < kTrialCount; i++) {
        Document doc;
        doc.Parse(json_, length_);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#7
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseIterative_MemoryPoolAllocator)) {
    for (size_t i = 0; i < kTrialCount; i++) {
        Document doc;
        doc.Parse<kParseIterativeFlag>(json_);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#8
0
void CubeSession::OnPackage(Package *&pack)
{
	if (!pack || pack->Header.DataLength == 0) return;
	pack->Data[pack->Header.DataLength - 1] = '\0';
	log_debug("on package (fd = %u): %s", static_cast<unsigned int>(fd), pack->Data);

	Document doc;
	doc.Parse(pack->Data);
	//  {"command": "cmd...", arg1: argv1, arg2: argv2, ...}
	do
	{
		if (!doc.IsObject())
		{
			SendError(SESSIONERROR_PROTOCOL_MISMATCH);
			break;
		}

		if (checkObj(doc, 1, "command", "str"))
		{
			handleCommand(doc);
		}
		else
		{
			SendError(SESSIONERROR_PROTOCOL_MISMATCH);
			break;
		}
	} while (false);

	delete pack;
	pack = NULL;
}
void LoginScene::onLoginResponse(HttpClient * sender, HttpResponse *response)
{
	if (!response) return;

	if (!response->isSucceed()) {
		log("response failed");
		log("error buffer: %s", response->getErrorBuffer());
		return;
	}

	string res = Global::toString(response->getResponseData());
	Document d;
	d.Parse<0>(res.c_str());

	if (d.HasParseError()) {
		CCLOG("GetParseError %s\n", d.GetParseError());
	}

	if (d.IsObject() && d.HasMember("result") && d.HasMember("info")) {
		bool result = d["result"].GetBool();
		if (result) {
			Global::saveStatus(response->getResponseHeader(), textField->getString());
			Director::getInstance()->replaceScene(TransitionFade::create(1, GameScene::createScene()));
		}
		else {
			CCLOG("Failed to login: %s\n", d["info"].GetString());
		}
	}
}
示例#10
0
/**
 * Constructor.
 * Initialised empty, optionally loading from a file or serialised string.
 * @param file The location of a file containing options, or nullptr if not present.
 * @param json_string The serialised JSON string to load, or nullptr if not present.
 *                    Will take precedence over the contents of the specified
 *                    file, if any.
 */
Options::Options(const char *file, const char *json_string) {
    Document *d = new Document();

    if (json_string) {
        d->Parse<0>(json_string);
    }

    if (file) {
        FILE *fp = fopen(file, "rb");
        if (fp) {
            if (!json_string) {
                char buffer[BUFSIZ];
                FileReadStream is(fp, buffer, sizeof(buffer));
                d->ParseStream<0, UTF8<>, FileReadStream>(is);
            }

            fclose(fp);
            m_file = std::string(file);
        }
    }

    if (!d->IsObject()) {
        d->SetObject();
        m_family_inst = nullptr;
    } else {
        Value *fi = LGetValue(d, FAMILY_DEFAULT);
        if (fi && !fi->IsObject()) {
            fi->SetObject();
        }
        m_family_inst = fi;
    }

    m_doc = d;
    m_family = FAMILY_DEFAULT;
}
void HostNamePartialControllerData::deserialize(Document& d) {
    if (d.IsObject()) {
        if (d.HasMember("data")) {
            Message::Value& v = d["data"];
            if (v.IsString()) data = std::string(v.GetString());
        }
    }
}
示例#12
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseStdString_MemoryPoolAllocator)) {
    const std::string s(json_, length_);
    for (size_t i = 0; i < kTrialCount; i++) {
        Document doc;
        doc.Parse(s);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#13
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseIterativeInsitu_MemoryPoolAllocator)) {
    for (size_t i = 0; i < kTrialCount; i++) {
        memcpy(temp_, json_, length_ + 1);
        Document doc;
        doc.ParseInsitu<kParseIterativeFlag>(temp_);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#14
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseEncodedInputStream_MemoryStream)) {
    for (size_t i = 0; i < kTrialCount; i++) {
        MemoryStream ms(json_, length_);
        EncodedInputStream<UTF8<>, MemoryStream> is(ms);
        Document doc;
        doc.ParseStream<0, UTF8<> >(is);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#15
0
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseAutoUTFInputStream_MemoryStream)) {
    for (size_t i = 0; i < kTrialCount; i++) {
        MemoryStream ms(json_, length_);
        AutoUTFInputStream<unsigned, MemoryStream> is(ms);
        Document doc;
        doc.ParseStream<0, AutoUTF<unsigned> >(is);
        ASSERT_TRUE(doc.IsObject());
    }
}
示例#16
0
void GBlurProcessor::init(const char* json) {
  // Read json string to set properties
  using namespace rapidjson;
  Document document;
  document.Parse(json);
  assert(document.IsObject());
  assert(document.HasMember("level"));
  level = document["level"].GetInt();
}
示例#17
0
void SobelProcessor::init(const char* json) {
  // Read json string to set properties
  using namespace rapidjson;
  Document document;
  document.Parse(json);
  assert(document.IsObject());
  assert(document.HasMember("ksize"));
  ksize = document["ksize"].GetInt();
}
TEST(IStreamWrapper, fstream)
{ fstream fs;
  ASSERT_TRUE(Open(fs, "utf8bom.json"));
  IStreamWrapper isw(fs);
  EncodedInputStream<UTF8<>, IStreamWrapper> eis(isw);
  Document d;
  EXPECT_TRUE(!d.ParseStream(eis).HasParseError());
  EXPECT_TRUE(d.IsObject());
  EXPECT_EQ(5, d.MemberCount());
}
	Config loadConfigAtPath(const std::string& config_path)
	{
		Document doc = loadDocument(config_path);
		assert(doc.IsObject());

		auto all_elements = getAllElements(doc);
		auto all_element_groups = getAllElementGroups(doc, all_elements);
		auto all_element_children = getAllElementChildren(doc, all_elements, all_element_groups);
		const auto& configuration = Config(std::move(all_elements), std::move(all_element_groups), std::move(all_element_children));
		return configuration;
	}
示例#20
0
void EyeTrackProcessor::init( const char* json ) {
  using namespace rapidjson;
  Document document;

  document.Parse(json);
  assert(document.IsObject());
  assert(document.HasMember("useQuantile"));
  useQuantile = document["useQuantile"].GetInt();
  gradThreshQuantile = document["qscale"].GetDouble();
  gradThreshStdScale = document["sscale"].GetDouble();
  ksize = document["ksize"].GetInt();
}
示例#21
0
TEST(BoatStateTest, SetWaypointAction) {
	VLOG(1) << "===Boat State Test, Command Set Waypoint Action===";
	BoatState me;
	Document d;
	Value default_val;
	d.Parse("{\"action\":\"Return\"}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("action"));
	EXPECT_NO_THROW(me.pushCmd("SetWaypointAction", d));
	VLOG(2) << "Action: " << me.waypointList.actionNames.get(me.waypointList.getAction());
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << "Action: " << me.waypointList.actionNames.get(me.waypointList.getAction());
	EXPECT_EQ(me.waypointList.getAction(), WaypointActionEnum::RETURN);
	d.Parse("{\"action\":\"\"}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("action"));
	EXPECT_NO_THROW(me.pushCmd("SetWaypointAction", d));
	EXPECT_EQ(me.executeCmds(1), 0);
	VLOG(2) << "Action: " << me.waypointList.actionNames.get(me.waypointList.getAction());
	EXPECT_EQ(me.waypointList.getAction(), WaypointActionEnum::RETURN);
}
示例#22
0
void ResultSet::mergeStream(istream& stream) {
  // Read input line by line
  string line;
  line.reserve(5 * 1024 * 1024); // just reserve enough memory
  int nb_line = 0;
  while (getline(stream, line)) {
    nb_line++;

    // Find tab
    size_t tab = line.find('\t');
    if (tab == string::npos) {
      fprintf(stderr, "No tab on line %i\n", nb_line);
      continue;
    }

    // Find second slash
    size_t slash = line.find('/');
    if (slash == string::npos) {
      fprintf(stderr, "No slash on line %i\n", nb_line);
      continue;
    }
    slash = line.find('/', slash + 1);
    if (slash == string::npos) {
      fprintf(stderr, "No channel/version on line %i\n", nb_line);
      continue;
    }

    // Find filePath
    string channelVersion = line.substr(0, slash);
    string measure        = line.substr(slash + 1, tab - slash - 1);

    // Parse JSON document
    Document d;
    d.Parse<0>(line.data() + tab + 1);

    // Check that we have an object
    if (!d.IsObject()) {
      fprintf(stderr, "JSON root is not an object on line %i\n", nb_line);
      continue;
    }

    // Find channel version in hash table
    auto it = _channelVersionMap.find(channelVersion);
    // If not present create ChannelVersion
    if (it == _channelVersionMap.end()) {
      auto cv = new ChannelVersion(_measureStringCtx, _filterStringCtx);
      it = _channelVersionMap.insert({channelVersion, cv}).first;
    }
    // Merge our data in
    it->second->mergeMeasureJSON(measure.data(), d);
  }
}
示例#23
0
    void ImageSequence::loadMetadata(string host) {
        // Curl out the metadata for this Id
        // Invoke the parser
        // Grab the metadata fields

        // URL: host/imageseq/id/describe

        char url[host.length() + 17 + 10];
        sprintf(url, "http://%s/imageseq/%u", host.c_str(), id);
        const char* metadataJSON = curlGet(url).c_str();

        // Parse metadata
        Document document;
        if(document.Parse<0>(metadataJSON).HasParseError()) {
            // Failed to parse
            fprintf(stderr, "Error Parsing metadata JSON");
            return;
        }

        if(document.IsObject()
            && document.HasMember("delta")
            && document.HasMember("count")
            && document.HasMember("images")
            && document.HasMember("description")) {
            // We have all the necessary fields

            length = document["count"].GetUint();
            delta  = document["delta"].GetInt() / 1000.0;

            if(!document["description"].IsNull()) {
                description = document["description"].GetString();
            } else {
                description = "";
            }

            // Pull out the image list
            if(document["images"].IsArray()) {
                for(uint32_t i=0; i<length; i++) {
                    // Take the ID and make an object
                    LabeledImage *newImage = 
                            new LabeledImage(document["images"][i].GetUint());
                    // Take the object and load its metadata
                    newImage->load(host);
                    images.push_back(newImage);
                }
            }

        } else {
            fprintf(stderr, "Image metadata is missing params");
        }

    }
示例#24
0
TEST(BoatStateTest, SetAutoMode) {
	VLOG(1) << "===Boat State Test, Command Auto Mode===";
	BoatState me;
	Document d;
	d.Parse("{\"mode\":\"Return\"}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("mode"));
	EXPECT_NO_THROW(me.pushCmd("SetAutoMode", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_EQ(me.getAutoMode(), AutoModeEnum::RETURN);
}
示例#25
0
TEST(BoatStateTest, SetPID) {
	VLOG(1) << "===Boat State Test, Command Set PID===";
	BoatState me;
	Document d;
	Value default_val;
	d.Parse("{\"Kp\":5.0}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("Kp"));
	EXPECT_NO_THROW(me.pushCmd("SetPID", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_TRUE(toleranceEquals(std::get<0>(me.K), 5.0, 0.0000001));
	EXPECT_TRUE(toleranceEquals(std::get<1>(me.K), 0.1, 0.0000001));
	EXPECT_TRUE(toleranceEquals(std::get<2>(me.K), 0.0, 0.0000001));
	d.Parse("{\"Ki\":0.5,\"Kd\":0.1}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("Ki"));
	ASSERT_TRUE(d.HasMember("Kd"));
	EXPECT_NO_THROW(me.pushCmd("SetPID", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_EQ(std::get<0>(me.K), 5.0);
	EXPECT_EQ(std::get<1>(me.K), 0.5);
	EXPECT_EQ(std::get<2>(me.K), 0.1);
	d.Parse("{\"Kp\":50.0,\"Ki\":5.0,\"Kd\":1.0}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("Kp"));
	ASSERT_TRUE(d.HasMember("Ki"));
	ASSERT_TRUE(d.HasMember("Kd"));
	EXPECT_NO_THROW(me.pushCmd("SetPID", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_EQ(std::get<0>(me.K), 50.0);
	EXPECT_EQ(std::get<1>(me.K), 5.0);
	EXPECT_EQ(std::get<2>(me.K), 1.0);
}
示例#26
0
void HostList::deserialize(Document& d) {
    if (d.IsObject() && d.HasMember("HOSTS")) {
        Message::Value& v = d["HOSTS"];
        if (v.IsArray()) {
            pthread_mutex_lock(&mutexHosts);
            hosts.clear();
            for (SizeType i = 0; i < v.Size(); i++) {
                if (v[i].IsString()) hosts.push_back(std::string(v[i].GetString()));
            }
            pthread_mutex_unlock(&mutexHosts);
        }
    }
}
示例#27
0
/**
 * Merge one set of options into this one.
 * All settings in the input take precedence over anything currently stored.
 * @param json_string The serialised JSON string to merge from.
 * @return true iff successfully merged.
 */
bool Options::Merge(const char *json_string) {
    if (json_string) {
        Document d;
        d.Parse<0>(json_string);
        if (!d.HasParseError() && d.IsObject()) {
            //Loop through each family
            for (Value::ConstMemberIterator it = d.MemberBegin();
                 it != d.MemberEnd(); it++)
            {
                //Do we have a family of options? (e.g. an object)
                if (it->value.IsObject()) {
                    SetFamily(it->name.GetString());
                    //Loop through each option
                    for (Value::ConstMemberIterator optit = it->value.MemberBegin();
                         optit != it->value.MemberEnd(); optit++)
                    {
                        const char *optkey = optit->name.GetString();
                        switch (optit->value.GetType()) {
                            case kFalseType: case kTrueType:
                                Set(optkey, optit->value.GetBool());
                            case kNumberType:
                                if (optit->value.IsInt()) {
                                    Set(optkey, optit->value.GetInt());
                                } else if (optit->value.IsNumber()) {
                                    Set(optkey, optit->value.GetDouble());
                                } else if (optit->value.IsBool()) {
                                    Set(optkey, optit->value.GetBool());
                                }
                            break;
                            case kStringType:
                                Set(optkey, optit->value.GetString());
                            break;
                            case kNullType: //Ignore
                            break;
                            default:
                                Log(LOG_WARNING, "Ignoring unknown option %s of type %d",
                                    optkey, optit->value.GetType());
                        }
                    }
                } else {
                    Log(LOG_WARNING, "Ignoring unknown family %s of type %d",
                        it->name.GetString(), it->value.GetType());
                }
            }
            return true;
        }
    }

    return false;
}
示例#28
0
TEST(BoatStateTest, SetNavMode) {
	VLOG(1) << "===Boat State Test, Command Nav Mode===";
	BoatState me;
	Document d;
	Value default_val;
	d.Parse("{\"mode\":\"Autonomous\"}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("mode"));
	EXPECT_NO_THROW(me.pushCmd("SetNavMode", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_EQ(me.getNavMode(), NavModeEnum::AUTONOMOUS);
}
示例#29
0
TEST(BoatStateTest, SetWaypoint) {
	VLOG(1) << "===Boat State Test, Command Set Waypoint===";
	BoatState me;
	Document d;
	Value default_val;
	me.waypointList.loadKML("/home/debian/hackerboat/embedded_software/unified/test_data/waypoint/test_map_1.kml");
	VLOG(2) << "Count: " << me.waypointList.count()
			<< ", current: " << me.waypointList.current()
			<< ", action: "
			<< me.waypointList.actionNames.get(me.waypointList.getAction());
	EXPECT_EQ(me.waypointList.count(), 7);
	EXPECT_EQ(me.waypointList.current(), 0);
	EXPECT_EQ(me.waypointList.getAction(), WaypointActionEnum::NONE);
	d.Parse("{\"number\":4}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("number"));
	EXPECT_NO_THROW(me.pushCmd("SetWaypoint", d));
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << "Count: " << me.waypointList.count() << ", current: " << me.waypointList.current();
	EXPECT_EQ(me.waypointList.current(), 4);
	d.Parse("{\"number\":8}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("number"));
	EXPECT_NO_THROW(me.pushCmd("SetWaypoint", d));
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << "Count: " << me.waypointList.count()
			<< ", current: " << me.waypointList.current();
	EXPECT_EQ(me.waypointList.current(), 6);
	d.Parse("{\"number\":-1}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("number"));
	EXPECT_NO_THROW(me.pushCmd("SetWaypoint", d));
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << "Count: " << me.waypointList.count() << ", current: " << me.waypointList.current();
	EXPECT_EQ(me.waypointList.current(), 0);
}
示例#30
0
TEST(BoatStateTest, SetHome) {
	VLOG(1) << "===Boat State Test, Command Set Home===";
	BoatState me;
	Document d;
	Value default_val;
	d.Parse("{\"location\":{\"lat\":5.0,\"lon\":7.5}}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("location"));
	EXPECT_NO_THROW(me.pushCmd("SetHome", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 1);
	VLOG(2) << me;
	EXPECT_EQ(me.launchPoint.lat, 5.0);
	EXPECT_EQ(me.launchPoint.lon, 7.5);
	d.Parse("{\"location\":{\"lon\":7.5}}");
	ASSERT_TRUE(d.IsObject());
	ASSERT_TRUE(d.HasMember("location"));
	EXPECT_NO_THROW(me.pushCmd("SetHome", d));
	VLOG(2) << me;
	EXPECT_EQ(me.executeCmds(1), 0);
	VLOG(2) << me;
	EXPECT_EQ(me.launchPoint.lat, 5.0);
	EXPECT_EQ(me.launchPoint.lon, 7.5);
}