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_cssdeclaration.h | 110 +++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 50 deletions(-) (limited to 'xfa/fde/css/fde_cssdeclaration.h') diff --git a/xfa/fde/css/fde_cssdeclaration.h b/xfa/fde/css/fde_cssdeclaration.h index 2dbd7a0622..bb8795c446 100644 --- a/xfa/fde/css/fde_cssdeclaration.h +++ b/xfa/fde/css/fde_cssdeclaration.h @@ -7,23 +7,27 @@ #ifndef XFA_FDE_CSS_FDE_CSSDECLARATION_H_ #define XFA_FDE_CSS_FDE_CSSDECLARATION_H_ +#include #include +#include +#include #include "xfa/fde/css/fde_cssdatatable.h" class FDE_CSSPropertyHolder { public: + FDE_CSSPropertyHolder(); + ~FDE_CSSPropertyHolder(); + FDE_CSSProperty eProperty; bool bImportant; - CFDE_CSSValue* pValue; - FDE_CSSPropertyHolder* pNext; + CFX_RetainPtr pValue; }; class FDE_CSSCustomProperty { public: const FX_WCHAR* pwsName; const FX_WCHAR* pwsValue; - FDE_CSSCustomProperty* pNext; }; struct FDE_CSSPropertyArgs { @@ -33,81 +37,87 @@ struct FDE_CSSPropertyArgs { class CFDE_CSSDeclaration { public: - CFDE_CSSDeclaration() - : m_pFirstProperty(nullptr), - m_pLastProperty(nullptr), - m_pFirstCustom(nullptr), - m_pLastCustom(nullptr) {} + using const_prop_iterator = + std::vector>::const_iterator; + using const_custom_iterator = + std::vector>::const_iterator; + + CFDE_CSSDeclaration(); + ~CFDE_CSSDeclaration(); CFDE_CSSValue* GetProperty(FDE_CSSProperty eProperty, bool& bImportant) const; - FX_POSITION GetStartPosition() const; - void GetNextProperty(FX_POSITION& pos, - FDE_CSSProperty& eProperty, - CFDE_CSSValue*& pValue, - bool& bImportant) const; - FX_POSITION GetStartCustom() const; - void GetNextCustom(FX_POSITION& pos, - CFX_WideString& wsName, - CFX_WideString& wsValue) const; - bool AddProperty(const FDE_CSSPropertyArgs* pArgs, + + const_prop_iterator begin() const { return properties_.begin(); } + const_prop_iterator end() const { return properties_.end(); } + + const_custom_iterator custom_begin() const { + return custom_properties_.begin(); + } + const_custom_iterator custom_end() const { return custom_properties_.end(); } + + bool empty() const { return properties_.empty(); } + + void AddProperty(const FDE_CSSPropertyArgs* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen); - bool AddProperty(const FDE_CSSPropertyArgs* pArgs, + void AddProperty(const FDE_CSSPropertyArgs* pArgs, const FX_WCHAR* pszName, int32_t iNameLen, const FX_WCHAR* pszValue, int32_t iValueLen); + size_t PropertyCountForTesting() const; + protected: - bool ParseFontProperty(const FDE_CSSPropertyArgs* pArgs, + void ParseFontProperty(const FDE_CSSPropertyArgs* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen, bool bImportant); bool ParseBorderProperty(const FX_WCHAR* pszValue, int32_t iValueLen, - CFDE_CSSValue*& pWidth) const; - bool ParseValueListProperty(const FDE_CSSPropertyArgs* pArgs, + CFX_RetainPtr& pWidth) const; + void ParseValueListProperty(const FDE_CSSPropertyArgs* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen, bool bImportant); - bool Add4ValuesProperty(const CFX_ArrayTemplate& list, + void Add4ValuesProperty(const std::vector>& list, bool bImportant, FDE_CSSProperty eLeft, FDE_CSSProperty eTop, FDE_CSSProperty eRight, FDE_CSSProperty eBottom); - CFDE_CSSValue* ParseNumber(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); - CFDE_CSSValue* ParseEnum(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); - CFDE_CSSValue* ParseColor(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); - CFDE_CSSValue* ParseURI(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); - CFDE_CSSValue* ParseString(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); - CFDE_CSSValue* ParseFunction(const FDE_CSSPropertyArgs* pArgs, - const FX_WCHAR* pszValue, - int32_t iValueLen); + CFX_RetainPtr ParseNumber(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); + CFX_RetainPtr ParseEnum(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); + CFX_RetainPtr ParseColor(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); + CFX_RetainPtr ParseURI(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); + CFX_RetainPtr ParseString(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); + CFX_RetainPtr ParseFunction(const FDE_CSSPropertyArgs* pArgs, + const FX_WCHAR* pszValue, + int32_t iValueLen); const FX_WCHAR* CopyToLocal(const FDE_CSSPropertyArgs* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen); void AddPropertyHolder(FDE_CSSProperty eProperty, - CFDE_CSSValue* pValue, + CFX_RetainPtr pValue, bool bImportant); - CFDE_CSSPrimitiveValue* NewNumberValue(FDE_CSSPrimitiveType eUnit, - FX_FLOAT fValue) const; - CFDE_CSSPrimitiveValue* NewEnumValue(FDE_CSSPropertyValue eValue) const; - - FDE_CSSPropertyHolder* m_pFirstProperty; - FDE_CSSPropertyHolder* m_pLastProperty; - FDE_CSSCustomProperty* m_pFirstCustom; - FDE_CSSCustomProperty* m_pLastCustom; + CFX_RetainPtr NewNumberValue( + FDE_CSSPrimitiveType eUnit, + FX_FLOAT fValue) const; + CFX_RetainPtr NewEnumValue( + FDE_CSSPropertyValue eValue) const; + + std::vector> properties_; + std::vector> custom_properties_; }; #endif // XFA_FDE_CSS_FDE_CSSDECLARATION_H_ -- cgit v1.2.3