/* Test with invalid URI */ void invalidTest() { ::toolkit::Inspector inspect("asdf://asdf"); isFalse(inspect.audio()); isFalse(inspect.video()); isTrue(inspect.title().empty()); isTrue(inspect.album().empty()); }
/* Test for creating directories from paths */ void makeDir() { ::core::Path path("tests/aaaaaaaaaaaaa"); isFalse(path.exists()); isTrue(path.create()); isTrue(path.exists()); isTrue(::core::Path::remove(path.toString())); isFalse(path.exists()); }
/* Test for path checking */ void checkPaths() { isTrue(::core::Path::exists(".")); isTrue(::core::Path::exists("tests")); isTrue(::core::Path::exists("tests/filesystem_tests.hpp")); isFalse(::core::Path::exists("aaaaaaaaaaaaaaaaaaaaaaaa")); ::core::Path path("tests"); isTrue(path.exists()); ::core::Path bad_path("aaaaaaaaaaaaaaaaaa"); isFalse(bad_path.exists()); }
/* **************************************************************************** * * Scope::check - */ std::string Scope::check(RequestType requestType, Format format, std::string indent, std::string predetectedError, int counter) { if (type == "FIWARE_Location") { if (areaType == orion::CircleType) { if (circle.radiusString() == "0") return "Radius zero for a circle area"; else if (circle.radiusString() == "") return "Missing radius for circle area"; else if (circle.invertedString() != "") { if (!isTrue(circle.invertedString()) && !isFalse(circle.invertedString())) return "bad value for circle/inverted: '" + circle.invertedString() + "'"; } else if (circle.center.latitudeString() == "") return "Missing latitude for circle center"; else if (circle.center.longitudeString() == "") return "Missing longitude for circle center"; } else if (areaType == orion::PolygonType) { if (polygon.vertexList.size() < 3) return "too few vertices for a polygon"; else if (polygon.invertedString() != "") { if (!isTrue(polygon.invertedString()) && !isFalse(polygon.invertedString())) return "bad value for polygon/inverted: '" + polygon.invertedString() + "'"; } for (unsigned int ix = 0; ix < polygon.vertexList.size(); ++ix) { if (polygon.vertexList[ix]->latitudeString() == "") return std::string("missing latitude value for polygon vertex"); if (polygon.vertexList[ix]->longitudeString() == "") return std::string("missing longitude value for polygon vertex"); } } } else { if (type == "") return "Empty type in restriction scope"; if (value == "") return "Empty value in restriction scope"; } return "OK"; }
/* Test with video file */ void videoTest() { ::toolkit::Inspector inspect("file://" + ::core::Path::current() + "/tests/video.ogg"); isFalse(inspect.audio()); isTrue(inspect.video()); isTrue(inspect.title().empty()); isTrue(inspect.album().empty()); }
/* Test with audio file */ void audioTest() { ::toolkit::Inspector inspect("file://" + ::core::Path::current() + "/tests/audio.ogg"); isTrue(inspect.audio()); isFalse(inspect.video()); equal(inspect.title(), "Test Audio"); equal(inspect.album(), "Test Album"); }
/* **************************************************************************** * * EntityId::check - */ std::string EntityId::check ( ConnectionInfo* ciP, RequestType requestType, const std::string& indent, const std::string& predetectedError, int counter ) { if (id == "") { return "empty entityId:id"; } if (!isTrue(isPattern) && !isFalse(isPattern) && isPattern != "") { return std::string("invalid isPattern value for entity: /") + isPattern + "/"; } if ((requestType == RegisterContext) && (isTrue(isPattern))) { return "isPattern set to true for registrations is currently not supported"; } if (isTrue(isPattern)) { regex_t re; if (regcomp(&re, id.c_str(), REG_EXTENDED) != 0) { return "invalid regex for entity id pattern"; } regfree(&re); } return "OK"; }
char* JSValue::description() { static const size_t size = 32; static char description[size]; if (!*this) snprintf(description, size, "<JSValue()>"); else if (isInt32()) snprintf(description, size, "Int32: %d", asInt32()); else if (isDouble()) snprintf(description, size, "Double: %lf", asDouble()); else if (isCell()) snprintf(description, size, "Cell: %p", asCell()); else if (isTrue()) snprintf(description, size, "True"); else if (isFalse()) snprintf(description, size, "False"); else if (isNull()) snprintf(description, size, "Null"); else { ASSERT(isUndefined()); snprintf(description, size, "Undefined"); } return description; }
/* **************************************************************************** * * ContextRegistrationAttribute::check - */ std::string ContextRegistrationAttribute::check ( RequestType requestType, Format format, const std::string& indent, const std::string& predetectedError, int counter ) { std::string errorString; if (name == "") { return "missing name for registration attribute"; } if (isDomain == "") { return "missing isDomain value for registration attribute"; } if (!isTrue(isDomain) && !isFalse(isDomain)) { return std::string("invalid isDomain value for registration attribute: /") + isDomain + "/"; } std::string res; if ((res = metadataVector.check(requestType, format, indent, predetectedError, counter)) != "OK") { return res; } return "OK"; }
/* **************************************************************************** * * EntityId::check - */ std::string EntityId::check ( RequestType requestType, Format format, const std::string& indent, const std::string& predetectedError, int counter ) { if (id == "") { return "empty entityId:id"; } if (!isTrue(isPattern) && !isFalse(isPattern) && isPattern != "") { return std::string("invalid isPattern value for entity: /") + isPattern + "/"; } if ((requestType == RegisterContext) && (isTrue(isPattern))) { return "isPattern set to true for a registration"; } return "OK"; }
inline Logical Logical::operator&&(Logical other) const { if (isFalse() || other.isFalse()) { return false; } if (isNA() || other.isNA()) { return NA(); } return true; }
/* **************************************************************************** * * entityIdIsPattern - */ static std::string entityIdIsPattern(std::string path, std::string value, ParseData* parseDataP) { LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); parseDataP->ncr.cerP->contextElement.entityId.isPattern = value; if (!isTrue(value) && !isFalse(value)) LM_W(("bad 'isPattern' value: '%s'", value.c_str())); return "OK"; }
JSObject* JSValue::toThisObjectSlowCase(ExecState* exec) const { ASSERT(!isCell()); if (isInt32() || isDouble()) return constructNumber(exec, asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, asValue()); ASSERT(isUndefinedOrNull()); return exec->globalThisValue(); }
/* **************************************************************************** * * entityIdIsPattern - */ static std::string entityIdIsPattern(std::string path, std::string value, ParseData* reqDataP) { LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); reqDataP->qcr.entityIdP->isPattern = value; if (!isTrue(value) && !isFalse(value)) return "bad 'isPattern' value: '" + value + "'"; return "OK"; }
/* **************************************************************************** * * entityIdIsPattern - */ static std::string entityIdIsPattern(std::string path, std::string value, ParseData* reqDataP) { LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); reqDataP->dcar.entityIdP->isPattern = value; if (!isTrue(value) && !isFalse(value)) return "invalid isPattern (boolean) value for entity: '" + value + "'"; return "OK"; }
/* **************************************************************************** * * entityIdIsPattern - */ static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* parseDataP) { LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); parseDataP->ncr.cerP->contextElement.entityId.isPattern = value; if (!isTrue(value) && !isFalse(value)) { return "invalid isPattern value for entity: /" + value + "/"; } return "OK"; }
/* **************************************************************************** * * entityIdIsPattern - */ static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) { LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); if (!isTrue(value) && !isFalse(value)) { return "invalid isPattern value for entity: /" + value + "/"; } reqDataP->scar.entityIdP->isPattern = value; return "OK"; }
/* **************************************************************************** * * EntityId::check - */ std::string EntityId::check(RequestType requestType, Format format, std::string indent, std::string predetectedError, int counter) { if (id == "") return "empty entityId:id"; if (!isTrue(isPattern) && !isFalse(isPattern) && isPattern != "") return std::string("invalid isPattern (boolean) value for entity: '") + isPattern + "'"; if ((requestType == RegisterContext) && (isTrue(isPattern))) return "'isPattern' set to true for a registration"; return "OK"; }
JSObject* JSValue::toObjectSlowCase(ExecState* exec) const { ASSERT(!isCell()); if (isInt32() || isDouble()) return constructNumber(exec, asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, asValue()); ASSERT(isUndefinedOrNull()); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); exec->setException(exception); return new (exec) JSNotAnObject(exec, exception); }
/* **************************************************************************** * * polygonInverted - */ static int polygonInverted(xml_node<>* node, ParseData* parseDataP) { LM_T(LmtParse, ("Got a polygonInverted: %s", node->value())); parseDataP->qcr.scopeP->polygon.invertedSet(node->value()); if (!isTrue(node->value()) && !isFalse(node->value())) { parseDataP->errorString = std::string("bad string for polygon/inverted: /") + node->value() + "/"; return 1; } return 0; }
JSValue JSValue::toThisSlowCase(ExecState* exec, ECMAMode ecmaMode) const { ASSERT(!isCell()); if (ecmaMode == StrictMode) return *this; if (isInt32() || isDouble()) return constructNumber(exec, exec->lexicalGlobalObject(), asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, exec->lexicalGlobalObject(), asValue()); ASSERT(isUndefinedOrNull()); return exec->globalThisValue(); }
/* **************************************************************************** * * circleInverted - */ static int circleInverted(xml_node<>* node, ParseData* parseDataP) { LM_T(LmtParse, ("Got a circleInverted: %s", node->value())); parseDataP->scr.scopeP->circle.invertedSet(std::string(node->value())); if (!isTrue(node->value()) && !isFalse(node->value())) { parseDataP->errorString = std::string("bad string for circle/inverted: /") + node->value() + "/"; return 1; } return 0; }
/* Test creating paths */ void createPaths() { ::core::Path empty_path; equal(empty_path.toString(), "/"); isTrue(empty_path.absolute()); ::core::Path ordinary_path("/an/ordinary/path"); equal(ordinary_path.toString(), "/an/ordinary/path"); isTrue(ordinary_path.absolute()); ::core::Path extra_separators("/path//with///extra/separators//"); equal(extra_separators.toString(), "/path/with/extra/separators"); isTrue(extra_separators.absolute()); ::core::Path with_dot("/a/path/with/./dot"); equal(with_dot.toString(), "/a/path/with/dot"); isTrue(with_dot.absolute()); ::core::Path with_dots("/a/path/with/../dots"); equal(with_dots.toString(), "/a/path/dots"); isTrue(with_dots.absolute()); ::core::Path relative_path("relative/path"); equal(relative_path.toString(), "relative/path"); isFalse(relative_path.absolute()); relative_path.set("./new/path/"); equal(relative_path.toString(), "new/path"); isFalse(relative_path.absolute()); ::core::Path path_start_dots("../starts/with/relative"); equal(path_start_dots.toString(), "../starts/with/relative"); isFalse(path_start_dots.absolute()); ::core::Path multiple_dots("./../starts/./with/../two/dots"); equal(multiple_dots.toString(), "../starts/two/dots"); isFalse(multiple_dots.absolute()); }
JSObject* JSValue::toObjectSlowCase(ExecState* exec, JSGlobalObject* globalObject) const { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); ASSERT(!isCell()); if (isInt32() || isDouble()) return constructNumber(exec, globalObject, asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, globalObject, asValue()); ASSERT(isUndefinedOrNull()); throwException(exec, scope, createNotAnObjectError(exec, *this)); return nullptr; }
LCPP_TestCase(Syntax_BuiltinFunctions, or) { auto pResult = LCPP_pNil; pResult = evalString("(or)"); CUT_ASSERT.isTrue(isFalse(pResult)); pResult = evalString("(or 1)"); CUT_ASSERT.isTrue(number::getInteger(pResult) == 1); pResult = evalString("(or 1 2)"); CUT_ASSERT.isTrue(number::getInteger(pResult) == 1); pResult = evalString("(or #f 1 2)"); CUT_ASSERT.isTrue(number::getInteger(pResult) == 1); }
String JSValue::toWTFStringSlowCase(ExecState* exec) const { VM& vm = exec->vm(); if (isInt32()) return vm.numericStrings.add(asInt32()); if (isDouble()) return vm.numericStrings.add(asDouble()); if (isTrue()) return vm.propertyNames->trueKeyword.string(); if (isFalse()) return vm.propertyNames->falseKeyword.string(); if (isNull()) return vm.propertyNames->nullKeyword.string(); if (isUndefined()) return vm.propertyNames->undefinedKeyword.string(); return toString(exec)->value(exec); }
JSString* JSValue::toStringSlowCase(ExecState* exec, bool returnEmptyStringOnError) const { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto errorValue = [&] () -> JSString* { if (returnEmptyStringOnError) return jsEmptyString(exec); return nullptr; }; ASSERT(!isString()); if (isInt32()) { auto integer = asInt32(); if (static_cast<unsigned>(integer) <= 9) return vm.smallStrings.singleCharacterString(integer + '0'); return jsNontrivialString(&vm, vm.numericStrings.add(integer)); } if (isDouble()) return jsString(&vm, vm.numericStrings.add(asDouble())); if (isTrue()) return vm.smallStrings.trueString(); if (isFalse()) return vm.smallStrings.falseString(); if (isNull()) return vm.smallStrings.nullString(); if (isUndefined()) return vm.smallStrings.undefinedString(); if (isSymbol()) { throwTypeError(exec, scope, ASCIILiteral("Cannot convert a symbol to a string")); return errorValue(); } ASSERT(isCell()); JSValue value = asCell()->toPrimitive(exec, PreferString); if (vm.exception()) return errorValue(); ASSERT(!value.isObject()); JSString* result = value.toString(exec); if (vm.exception()) return errorValue(); return result; }
void JSValue::dumpForBacktrace(PrintStream& out) const { if (!*this) out.print("<JSValue()>"); else if (isInt32()) out.printf("%d", asInt32()); else if (isDouble()) out.printf("%lf", asDouble()); else if (isCell()) { if (asCell()->inherits(JSString::info())) { JSString* string = jsCast<JSString*>(asCell()); const StringImpl* impl = string->tryGetValueImpl(); if (impl) out.print("\"", impl, "\""); else out.print("(unresolved string)"); } else if (asCell()->inherits(Structure::info())) { out.print("Structure[ ", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } else { out.print("Cell[", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } } else if (isTrue()) out.print("True"); else if (isFalse()) out.print("False"); else if (isNull()) out.print("Null"); else if (isUndefined()) out.print("Undefined"); else out.print("INVALID"); }
/* **************************************************************************** * * isFalse - */ TEST(commonGlobals, isFalse) { bool bFalse; bFalse = isFalse("FALSE"); EXPECT_TRUE(bFalse) << "'FALSE' should be false"; bFalse = isFalse("False"); EXPECT_TRUE(bFalse) << "'False' should be false"; bFalse = isFalse("false"); EXPECT_TRUE(bFalse) << "'false' should be false"; bFalse = isFalse("NO"); EXPECT_TRUE(bFalse) << "'NO' should be false"; bFalse = isFalse("No"); EXPECT_TRUE(bFalse) << "'No' should be false"; bFalse = isFalse("no"); EXPECT_TRUE(bFalse) << "'no' should be false"; }
void JSValue::dumpInContextAssumingStructure( PrintStream& out, DumpContext* context, Structure* structure) const { if (!*this) out.print("<JSValue()>"); else if (isInt32()) out.printf("Int32: %d", asInt32()); else if (isDouble()) { #if USE(JSVALUE64) out.printf("Double: %lld, %lf", (long long)reinterpretDoubleToInt64(asDouble()), asDouble()); #else union { double asDouble; uint32_t asTwoInt32s[2]; } u; u.asDouble = asDouble(); out.printf("Double: %08x:%08x, %lf", u.asTwoInt32s[1], u.asTwoInt32s[0], asDouble()); #endif } else if (isCell()) { if (structure->classInfo()->isSubClassOf(JSString::info())) { JSString* string = jsCast<JSString*>(asCell()); out.print("String"); if (string->isRope()) out.print(" (rope)"); const StringImpl* impl = string->tryGetValueImpl(); if (impl) { if (impl->isAtomic()) out.print(" (atomic)"); if (impl->isAtomic()) out.print(" (identifier)"); if (impl->isSymbol()) out.print(" (symbol)"); } else out.print(" (unresolved)"); out.print(": ", impl); } else if (structure->classInfo()->isSubClassOf(Symbol::info())) out.print("Symbol: ", RawPointer(asCell())); else if (structure->classInfo()->isSubClassOf(Structure::info())) out.print("Structure: ", inContext(*jsCast<Structure*>(asCell()), context)); else if (structure->classInfo()->isSubClassOf(JSObject::info())) { out.print("Object: ", RawPointer(asCell())); out.print(" with butterfly ", RawPointer(asObject(asCell())->butterfly())); out.print(" (", inContext(*structure, context), ")"); } else { out.print("Cell: ", RawPointer(asCell())); out.print(" (", inContext(*structure, context), ")"); } #if USE(JSVALUE64) out.print(", ID: ", asCell()->structureID()); #endif } else if (isTrue()) out.print("True"); else if (isFalse()) out.print("False"); else if (isNull()) out.print("Null"); else if (isUndefined()) out.print("Undefined"); else out.print("INVALID"); }