Refactor python labelCompare() to use the new version API, add more tests
This commit is contained in:
parent
d88b929998
commit
74dd240d00
|
@ -4,6 +4,7 @@
|
|||
#include <rpm/rpmtag.h>
|
||||
#include <rpm/rpmstring.h>
|
||||
#include <rpm/rpmts.h> /* XXX rpmtsCreate/rpmtsFree */
|
||||
#include <rpm/rpmver.h>
|
||||
|
||||
#include "header-py.h"
|
||||
#include "rpmds-py.h"
|
||||
|
@ -888,36 +889,27 @@ PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds)
|
|||
return Py_BuildValue("i", rpmVersionCompare(h1->h, h2->h));
|
||||
}
|
||||
|
||||
static int compare_values(const char *str1, const char *str2)
|
||||
{
|
||||
if (!str1 && !str2)
|
||||
return 0;
|
||||
else if (str1 && !str2)
|
||||
return 1;
|
||||
else if (!str1 && str2)
|
||||
return -1;
|
||||
return rpmvercmp(str1, str2);
|
||||
}
|
||||
|
||||
PyObject * labelCompare (PyObject * self, PyObject * args)
|
||||
{
|
||||
const char *v1, *r1, *v2, *r2;
|
||||
const char *e1, *e2;
|
||||
int rc;
|
||||
PyObject *rco = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "(zzz)(zzz)",
|
||||
&e1, &v1, &r1, &e2, &v2, &r2))
|
||||
return NULL;
|
||||
|
||||
if (e1 == NULL) e1 = "0";
|
||||
if (e2 == NULL) e2 = "0";
|
||||
rpmver rv1 = rpmverNew(e1, v1, r1);
|
||||
rpmver rv2 = rpmverNew(e2, v2, r2);
|
||||
|
||||
rc = compare_values(e1, e2);
|
||||
if (!rc) {
|
||||
rc = compare_values(v1, v2);
|
||||
if (!rc)
|
||||
rc = compare_values(r1, r2);
|
||||
}
|
||||
return Py_BuildValue("i", rc);
|
||||
if (rv1 && rv2)
|
||||
rco = Py_BuildValue("i", rpmverCmp(rv1, rv2));
|
||||
else
|
||||
PyErr_SetString(PyExc_ValueError, "invalid version label");
|
||||
|
||||
rpmverFree(rv1);
|
||||
rpmverFree(rv2);
|
||||
|
||||
return rco;
|
||||
}
|
||||
|
||||
|
|
|
@ -155,8 +155,29 @@ h['release'] = r
|
|||
h['epoch'] = e
|
||||
myprint(rpm.labelCompare((str(h['epoch']), h['version'], h['release']),
|
||||
(str(e), v, r)))
|
||||
myprint(rpm.labelCompare((None, '1.0', '1'),
|
||||
(None, '1.1', '2')))
|
||||
myprint(rpm.labelCompare((None, '1.0', '1'),
|
||||
(None, '1.1', '1')))
|
||||
myprint(rpm.labelCompare((None, '1.1', '1'),
|
||||
(None, '1.0', '1')))
|
||||
myprint(rpm.labelCompare((None, '1.1', '1'),
|
||||
(None, '1.0', '2')))
|
||||
myprint(rpm.labelCompare(('1', '1.0', '1'),
|
||||
('0', '1.0', '1')))
|
||||
myprint(rpm.labelCompare(('0', '1.0', '1'),
|
||||
('1', '1.0', '1')))
|
||||
myprint(rpm.labelCompare(('0', '1.0', '1'),
|
||||
(None, '1.0', '1')))
|
||||
],
|
||||
[0]
|
||||
[0
|
||||
-1
|
||||
-1
|
||||
1
|
||||
1
|
||||
1
|
||||
-1
|
||||
0]
|
||||
)
|
||||
|
||||
RPMPY_TEST([vfyflags API],[
|
||||
|
|
Loading…
Reference in New Issue