From 3285c56b0dd6b83c2fcc8b8f714324185a09c920 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 17 Jan 2017 16:35:16 -0500 Subject: Start CSS parser unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Start adding unit tests for the css parser. Fixup memory leaks that are exposed by the tests. Change-Id: Id863d9cd5f13ab82626bc7b945de925253c88d43 Reviewed-on: https://pdfium-review.googlesource.com/2180 Reviewed-by: Nicolás Peña Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fde/css/fde_cssstyleselector.cpp | 39 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'xfa/fde/css/fde_cssstyleselector.cpp') diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 5e981d96eb..e6ee18f245 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -280,14 +280,15 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( int32_t iDeclCount, CFDE_CSSComputedStyle* pDestStyle) { CFDE_CSSComputedStyle* pComputedStyle = pDestStyle; - CFDE_CSSValue* pVal; - bool bImportant; + int32_t i; if (bPriority) { CFDE_CSSValue* pLastest = nullptr; CFDE_CSSValue* pImportant = nullptr; for (i = 0; i < iDeclCount; ++i) { - pVal = ppDeclArray[i]->GetProperty(FDE_CSSProperty::FontSize, bImportant); + bool bImportant; + CFDE_CSSValue* pVal = + ppDeclArray[i]->GetProperty(FDE_CSSProperty::FontSize, bImportant); if (!pVal) continue; @@ -304,39 +305,33 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( } else { CFX_ArrayTemplate importants; const CFDE_CSSDeclaration* pDecl = nullptr; - FDE_CSSProperty eProp; - FX_POSITION pos; + for (i = 0; i < iDeclCount; ++i) { pDecl = ppDeclArray[i]; - pos = pDecl->GetStartPosition(); - while (pos) { - pDecl->GetNextProperty(pos, eProp, pVal, bImportant); - if (eProp == FDE_CSSProperty::FontSize) { + for (auto it = pDecl->begin(); it != pDecl->end(); it++) { + if ((*it)->eProperty == FDE_CSSProperty::FontSize) continue; - } else if (!bImportant) { - ApplyProperty(eProp, pVal, pComputedStyle); + if (!(*it)->bImportant) { + ApplyProperty((*it)->eProperty, (*it)->pValue.Get(), pComputedStyle); } else if (importants.GetSize() == 0 || importants[importants.GetUpperBound()] != pDecl) { importants.Add(const_cast(pDecl)); } } } + iDeclCount = importants.GetSize(); for (i = 0; i < iDeclCount; ++i) { pDecl = importants[i]; - pos = pDecl->GetStartPosition(); - while (pos) { - pDecl->GetNextProperty(pos, eProp, pVal, bImportant); - if (bImportant && eProp != FDE_CSSProperty::FontSize) { - ApplyProperty(eProp, pVal, pComputedStyle); - } + + for (auto it = pDecl->begin(); it != pDecl->end(); it++) { + if ((*it)->bImportant && (*it)->eProperty != FDE_CSSProperty::FontSize) + ApplyProperty((*it)->eProperty, (*it)->pValue.Get(), pComputedStyle); } } - CFX_WideString wsName, wsValue; - pos = pDecl->GetStartCustom(); - while (pos) { - pDecl->GetNextCustom(pos, wsName, wsValue); - pComputedStyle->AddCustomStyle(wsName, wsValue); + + for (auto it = pDecl->custom_begin(); it != pDecl->custom_end(); it++) { + pComputedStyle->AddCustomStyle((*it)->pwsName, (*it)->pwsValue); } } } -- cgit v1.2.3