diff --git a/src/message_api.cc b/src/message_api.cc index e73053b..09a8aec 100644 --- a/src/message_api.cc +++ b/src/message_api.cc @@ -62,9 +62,9 @@ namespace pEp { return boost::python::make_tuple(dst, keylist, _rating, _flags); } - int _color(int rating) + PEP_color _color(int rating) { - return (int) ::color_from_rating((PEP_rating) rating); + return ::color_from_rating((PEP_rating) rating); } boost::python::tuple sync_decode(object buffer) diff --git a/src/message_api.hh b/src/message_api.hh index b6afcba..ecc3a02 100644 --- a/src/message_api.hh +++ b/src/message_api.hh @@ -10,7 +10,7 @@ namespace pEp { Message encrypt_message(Message src, boost::python::list extra = boost::python::list(), int enc_format = 4, int flags = 0); boost::python::tuple decrypt_message(Message src, int flags=0); - int _color(int rating); + PEP_color _color(int rating); object sync_search(string name); object distribution_search(string name); } diff --git a/test/doctest_PYADPT-55.py b/test/doctest_PYADPT-55.py new file mode 100644 index 0000000..592eb81 --- /dev/null +++ b/test/doctest_PYADPT-55.py @@ -0,0 +1,50 @@ +# Regression test against API breakage +# colors used to be represented as a simple int +# NEW: colors are represented by PEP_color enum +# Test for equal resolution of colors using int (OLD) vs using PEP_color (NEW) + +""" +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_no_color) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_yellow) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_green) +True +>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_red) +True +""" + + + +import pEp +# resolves a color represented as int, the OLD way +# returns PEP_color +def resolveColorOLD(col): + ret = pEp.PEP_color() + + c = pEp.PEP_color(col) + if(c == 0): + ret = pEp.PEP_color.PEP_color_no_color + if(c == 1): + ret = pEp.PEP_color.PEP_color_yellow + if(c == 2): + ret = pEp.PEP_color.PEP_color_green + if(c == -1): + ret = pEp.PEP_color.PEP_color_red + + return ret + +# resolves a color represented as PEP_color, the NEW way +# returns PEP_color +def resolveColorNEW(col): + c = pEp.PEP_color(col) + return col + +# Compare color resolution OLD vs NEW way +# return True if results are equal +def resolveOLDvsNEW(col): + return resolveColorOLD(col) == resolveColorNEW(col) + +if __name__ == "__main__": + import doctest + doctest.testmod()