TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { const FX_WCHAR* buf = L"a { border: 10px; }\nb { text-decoration: underline; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(2, sheet_->CountRules()); CFDE_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(1UL, style->CountSelectorLists()); bool found_selector = false; uint32_t hash = FX_HashCode_GetW(L"a", true); for (size_t i = 0; i < style->CountSelectorLists(); i++) { if (style->GetSelectorList(i)->GetNameHash() == hash) { found_selector = true; break; } } EXPECT_TRUE(found_selector); decl_ = style->GetDeclaration(); EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, FDE_CSSNumberType::Pixels); style = sheet_->GetRule(1); EXPECT_EQ(1UL, style->CountSelectorLists()); found_selector = false; hash = FX_HashCode_GetW(L"b", true); for (size_t i = 0; i < style->CountSelectorLists(); i++) { if (style->GetSelectorList(i)->GetNameHash() == hash) { found_selector = true; break; } } EXPECT_TRUE(found_selector); decl_ = style->GetDeclaration(); EXPECT_EQ(1UL, decl_->PropertyCountForTesting()); VerifyList(FDE_CSSProperty::TextDecoration, {FDE_CSSPropertyValue::Underline}); }
nsFrameList::Slice nsFrameList::InsertFrames(nsIFrame* aParent, nsIFrame* aPrevSibling, nsFrameList& aFrameList) { NS_PRECONDITION(aFrameList.NotEmpty(), "Unexpected empty list"); if (aParent) { aFrameList.ApplySetParent(aParent); } NS_ASSERTION(IsEmpty() || FirstChild()->GetParent() == aFrameList.FirstChild()->GetParent(), "frame to add has different parent"); NS_ASSERTION(!aPrevSibling || aPrevSibling->GetParent() == aFrameList.FirstChild()->GetParent(), "prev sibling has different parent"); #ifdef DEBUG_FRAME_LIST // ContainsFrame is O(N) NS_ASSERTION(!aPrevSibling || ContainsFrame(aPrevSibling), "prev sibling is not on this list"); #endif nsIFrame* firstNewFrame = aFrameList.FirstChild(); nsIFrame* nextSibling; if (aPrevSibling) { nextSibling = aPrevSibling->GetNextSibling(); aPrevSibling->SetNextSibling(firstNewFrame); } else { nextSibling = mFirstChild; mFirstChild = firstNewFrame; } nsIFrame* lastNewFrame = aFrameList.LastChild(); lastNewFrame->SetNextSibling(nextSibling); if (!nextSibling) { mLastChild = lastNewFrame; } VerifyList(); aFrameList.Clear(); return Slice(*this, firstNewFrame, nextSibling); }
static PyObject* Node_output(Node *self, PyObject *inputs) { if (!VerifyList(inputs)) { PyErr_Format(PyExc_ValueError, "The input is not a one dimension numpy list of type Double, or not a python list."); return NULL; } else if (!VerifySelf(self)) { PyErr_Format(PyExc_ValueError, "The weights vector is empty or an internal pointer is NULL: %d (1 for yes)", (self->weights == NULL || self->function == NULL || self->derivative == NULL)); return NULL; } else { double val; if (_Node_output(self, inputs, &val)) { return Py_BuildValue("d", val); } else return NULL; } }
static PyObject* Node_output_derivative(Node *self, PyObject *inputs) { if (!VerifyList(inputs)) { PyErr_Format(PyExc_ValueError, "The input is not a one dimension numpy list of type Double, or not a python list."); return NULL; } else if (!VerifySelf(self)) { PyErr_Format(PyExc_ValueError, "The weights vector is empty or an internal pointer is NULL: %d (1 for yes)", (self->weights == NULL || self->function == NULL || self->derivative == NULL)); return NULL; } else { //if (inputs != self->cached_input) { // Disable caching for now double output; if (!_Node_output(self, inputs, &output)) return NULL; //} return Py_BuildValue("d", self->derivative(self->cached_output)); } }
/** * Computes a list of s-attributes to print from the PrintStructure global option setting. * * PrintStructure is itself updated. * * @param cl The corpus from which to find the attributes. * @return An attribute list containing the attributes to be printed. */ AttributeList * ComputePrintStructures(CorpusList *cl) { if (printStructure == NULL || printStructure[0] == '\0' || cl == NULL) return NULL; else { char *token, *p; AttributeList *al; AttributeInfo *ai; Attribute *struc; al = NULL; struc = NULL; token = strtok(printStructure, PRINT_STRUC_SEP); if (!token) return NULL; while (token) { if ((struc = find_attribute(cl->corpus, token, ATT_STRUC, NULL)) == NULL) { cqpmessage(Warning, "Structure ``%s'' not declared for corpus ``%s''.", token, cl->corpus->registry_name); } else if (!structure_has_values(struc)) { cqpmessage(Warning, "Structure ``%s'' does not have any values.", token); struc = NULL; } if (struc) { if (al == NULL) al = NewAttributeList(ATT_STRUC); (void) AddNameToAL(al, token, 1, 0); } token = strtok(NULL, PRINT_STRUC_SEP); } if (al) { if (!VerifyList(al, cl->corpus, 1)) { cqpmessage(Error, "Problems while computing print structure list"); DestroyAttributeList(&al); al = NULL; } else if (!al->list) DestroyAttributeList(&al); } /* rebuild printStructure string to show only valid attributes */ p = printStructure; *p = '\0'; ai = (al) ? al->list : NULL; while (ai != NULL) { if (p != printStructure) *p++ = ' '; /* insert blank between attributes */ sprintf(p, "%s", ai->attribute->any.name); p += strlen(p); ai = ai->next; } return al; } assert(0 && "Not reached ;-|"); return NULL; }
/** * Verify the current context settings against the current corpus: * check whether structures are still valid, and reset them to * defaults if not. returns 1 if all keeps the same, 0 otherwise. The * string fields in CD are supposed to be malloced and freed. */ int verify_context_descriptor(Corpus *corpus, ContextDescriptor *cd, int remove_illegal_entries) { int result = 1; if (cd == NULL) { Rprintf( "verify_context_descriptor(): WARNING: Context Descriptor empty!\n"); result = 0; } else if (corpus == NULL) { Rprintf( "verify_context_descriptor(): WARNING: Corpus Descriptor empty!\n"); RESET_LEFT_CONTEXT; RESET_RIGHT_CONTEXT; cd->attributes = NULL; result = 0; } else { /* check left attribute */ if (cd->left_type == STRUC_CONTEXT) { if (cd->left_structure_name == NULL) { RESET_LEFT_CONTEXT; result = 0; } else { /* find (structural) attribute */ if ((cd->left_structure = find_attribute(corpus, cd->left_structure_name, ATT_STRUC, NULL)) == NULL) { /* not defined -> try alignment attribute */ if ((cd->left_structure = find_attribute(corpus, cd->left_structure_name, ATT_ALIGN, NULL)) == NULL) { /* error -> reset to default context */ RESET_LEFT_CONTEXT; result = 0; } else { /* alignment attribute found -> change context type to ALIGN_CONTEXT */ cd->left_type = ALIGN_CONTEXT; if (cd->left_width != 1) { cqpmessage(Warning, "Left Context '%d %s' changed to '1 %s' (alignment attribute).", cd->left_width, cd->left_structure_name, cd->left_structure_name); cd->left_width = 1; } } } } } if (cd->left_width < 0) { Rprintf( "concordance.o/verify_context_descriptor: WARNING: lwidth < 0\n"); cd->left_width = -cd->left_width; result = 0; } /* check right attribute */ if (cd->right_type == STRUC_CONTEXT) { if (cd->right_structure_name == NULL) { RESET_RIGHT_CONTEXT; result = 0; } else { /* find (structural) attribute */ if ((cd->right_structure = find_attribute(corpus, cd->right_structure_name, ATT_STRUC, NULL)) == NULL) { /* not defined -> try alignment attribute */ if ((cd->right_structure = find_attribute(corpus, cd->right_structure_name, ATT_ALIGN, NULL)) == NULL) { /* error -> reset to default context */ RESET_RIGHT_CONTEXT; result = 0; } else { /* alignment attribute found -> change context type to ALIGN_CONTEXT */ cd->right_type = ALIGN_CONTEXT; if (cd->right_width != 1) { cqpmessage(Warning, "Right Context '%d %s' changed to '1 %s' (alignment attribute).", cd->right_width, cd->right_structure_name, cd->right_structure_name); cd->right_width = 1; } } } } } if (cd->right_width < 0) { Rprintf( "concordance.o/verify_context_descriptor: WARNING: lwidth < 0\n"); cd->right_width = -cd->right_width; result = 0; } /* cd->print_cpos = 0; */ VerifyList(cd->attributes, corpus, remove_illegal_entries); if (cd->attributes && cd->attributes->list == NULL) DestroyAttributeList(&(cd->attributes)); VerifyList(cd->strucAttributes, corpus, remove_illegal_entries); if (cd->strucAttributes && cd->strucAttributes->list == NULL) DestroyAttributeList(&(cd->strucAttributes)); VerifyList(cd->printStructureTags, corpus, remove_illegal_entries); if (cd->printStructureTags && cd->printStructureTags->list == NULL) DestroyAttributeList(&(cd->printStructureTags)); VerifyList(cd->alignedCorpora, corpus, remove_illegal_entries); if (cd->alignedCorpora && cd->alignedCorpora->list == NULL) DestroyAttributeList(&(cd->alignedCorpora)); } return result; }