Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPN-6799: Add tests for timeToMainScreen metric #10172

Merged
merged 10 commits into from
Jan 9, 2025
2 changes: 1 addition & 1 deletion qtglean/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ execute_process(

## Add a static library for the Glean C++ code.
add_library(qtglean STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/basemetric.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/boolean.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/datetime.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/quantity.h
Expand All @@ -20,7 +21,6 @@ add_library(qtglean STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/customdistribution.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/event.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/ping.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/distributiondata.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/timingdistribution.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/memorydistribution.h
${CMAKE_CURRENT_SOURCE_DIR}/include/glean/uuid.h
Expand Down
26 changes: 26 additions & 0 deletions qtglean/include/glean/basemetric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BASEMETRIC_H
#define BASEMETRIC_H
#include <QObject>

#include "errortype.h"

class BaseMetric : public QObject {
Q_OBJECT
Q_DISABLE_COPY_MOVE(BaseMetric)

public:
explicit BaseMetric(int aId) : m_id(aId){};

// Test only functions
virtual QJsonValue testGetValue(const QString& pingName = "") const = 0;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const = 0;

protected:
const int m_id;
};

#endif // BASEMETRIC_H
10 changes: 4 additions & 6 deletions qtglean/include/glean/boolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define BOOLEAN_H
#include <QObject>

#include "basemetric.h"
#include "errortype.h"

class BooleanMetric final : public QObject {
class BooleanMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(BooleanMetric)

Expand All @@ -18,11 +19,8 @@ class BooleanMetric final : public QObject {
Q_INVOKABLE void set(bool value = true) const;

// Test only functions
Q_INVOKABLE bool testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // BOOLEAN_H
11 changes: 4 additions & 7 deletions qtglean/include/glean/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define COUNTER_H
#include <QObject>

#include "basemetric.h"
#include "errortype.h"

class CounterMetric final : public QObject {
class CounterMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(CounterMetric)

Expand All @@ -18,12 +19,8 @@ class CounterMetric final : public QObject {
Q_INVOKABLE void add(int amount = 1) const;

// Test only functions

Q_INVOKABLE int32_t testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // COUNTER_H
12 changes: 4 additions & 8 deletions qtglean/include/glean/customdistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <QHash>
#include <QObject>

#include "distributiondata.h"
#include "basemetric.h"
#include "errortype.h"

class CustomDistributionMetric final : public QObject {
class CustomDistributionMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(CustomDistributionMetric)

Expand All @@ -21,12 +21,8 @@ class CustomDistributionMetric final : public QObject {
Q_INVOKABLE void accumulate_single_sample(qint64 sample) const;

// Test only functions

Q_INVOKABLE DistributionData testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // CUSTOM_DISTRIBUTION_H
12 changes: 4 additions & 8 deletions qtglean/include/glean/datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include <QObject>
#include <QString>

#include "basemetric.h"
#include "errortype.h"

// NOTE: While most of datetime is implemented, one piece is not yet:
// - The ability to set an arbitrary datestamp
// More details: https://mozilla-hub.atlassian.net/browse/VPN-4173

class DatetimeMetric final : public QObject {
class DatetimeMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(DatetimeMetric)

Expand All @@ -25,13 +26,8 @@ class DatetimeMetric final : public QObject {
Q_INVOKABLE void set() const;

// Test only functions

Q_INVOKABLE QDateTime testGetValue(const QString& pingName = "") const;
Q_INVOKABLE QString testGetValueAsString(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // DATETIME_H
27 changes: 0 additions & 27 deletions qtglean/include/glean/distributiondata.h

This file was deleted.

11 changes: 5 additions & 6 deletions qtglean/include/glean/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QJsonObject>
#include <QObject>

#include "basemetric.h"
#include "errortype.h"

struct FfiExtra {
Expand Down Expand Up @@ -54,7 +55,7 @@ struct EventMetricExtraParser {
}
};

class EventMetric final : public QObject {
class EventMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(EventMetric)

Expand All @@ -70,13 +71,11 @@ class EventMetric final : public QObject {

void record(const EventMetricExtra& extras);

Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

Q_INVOKABLE QList<QJsonObject> testGetValue(
const QString& pingName = "") const;
// Test only functions
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
EventMetricExtraParser* m_parser;
};

Expand Down
12 changes: 4 additions & 8 deletions qtglean/include/glean/memorydistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QHash>
#include <QObject>

#include "distributiondata.h"
#include "basemetric.h"
#include "errortype.h"

// !!!IMPORTANT!!!
Expand All @@ -20,7 +20,7 @@
// stayed in so that this work is not lost, in the event we want to use
// this data type in the future.

class MemoryDistributionMetric final : public QObject {
class MemoryDistributionMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(MemoryDistributionMetric)

Expand All @@ -30,12 +30,8 @@ class MemoryDistributionMetric final : public QObject {
Q_INVOKABLE void accumulate(qint64 sample) const;

// Test only functions

Q_INVOKABLE DistributionData testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // MEMORY_DISTRIBUTION_H
1 change: 1 addition & 0 deletions qtglean/include/glean/metrictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef METRICTYPES_H
#define METRICTYPES_H

#include "basemetric.h"
#include "boolean.h"
#include "counter.h"
#include "customdistribution.h"
Expand Down
11 changes: 4 additions & 7 deletions qtglean/include/glean/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#include <QObject>

#include "basemetric.h"
#include "errortype.h"

class QuantityMetric final : public QObject {
class QuantityMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(QuantityMetric)

Expand All @@ -19,12 +20,8 @@ class QuantityMetric final : public QObject {
Q_INVOKABLE void set(int value = 0) const;

// Test only functions

Q_INVOKABLE int64_t testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // QUANTITY_H
11 changes: 4 additions & 7 deletions qtglean/include/glean/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <QObject>
#include <QString>

#include "basemetric.h"
#include "errortype.h"

class StringMetric final : public QObject {
class StringMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(StringMetric)

Expand All @@ -19,12 +20,8 @@ class StringMetric final : public QObject {
Q_INVOKABLE void set(QString value = "") const;

// Test only functions

Q_INVOKABLE QString testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // STRING_H
12 changes: 4 additions & 8 deletions qtglean/include/glean/timingdistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <QHash>
#include <QObject>

#include "distributiondata.h"
#include "basemetric.h"
#include "errortype.h"

class TimingDistributionMetric final : public QObject {
class TimingDistributionMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(TimingDistributionMetric)

Expand All @@ -23,12 +23,8 @@ class TimingDistributionMetric final : public QObject {
Q_INVOKABLE void cancel(qint64 timerId) const;

// Test only functions

Q_INVOKABLE DistributionData testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // TIMING_DISTRIBUTION_H
10 changes: 4 additions & 6 deletions qtglean/include/glean/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define UUID_H
#include <QObject>

#include "basemetric.h"
#include "errortype.h"

class UuidMetric final : public QObject {
class UuidMetric final : public BaseMetric {
Q_OBJECT
Q_DISABLE_COPY_MOVE(UuidMetric)

Expand All @@ -20,11 +21,8 @@ class UuidMetric final : public QObject {
Q_INVOKABLE QString generateAndSet() const;

// Test only functions
Q_INVOKABLE QString testGetValue(const QString& pingName = "") const;
Q_INVOKABLE int32_t testGetNumRecordedErrors(ErrorType errorType) const;

private:
const int m_id;
virtual QJsonValue testGetValue(const QString& pingName = "") const;
virtual int32_t testGetNumRecordedErrors(ErrorType errorType) const;
};

#endif // UUID_H
9 changes: 5 additions & 4 deletions qtglean/src/cpp/boolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "glean/boolean.h"

#include <QDebug>
#include <QJsonValue>

#ifndef __wasm__
# include "qtglean.h"
#endif

BooleanMetric::BooleanMetric(int id) : m_id(id) {}
BooleanMetric::BooleanMetric(int id) : BaseMetric(id) {}

void BooleanMetric::set(bool value) const {
#ifndef __wasm__
Expand All @@ -25,9 +26,9 @@ int32_t BooleanMetric::testGetNumRecordedErrors(ErrorType errorType) const {
return 0;
}

bool BooleanMetric::testGetValue(const QString& pingName) const {
QJsonValue BooleanMetric::testGetValue(const QString& pingName) const {
#ifndef __wasm__
return glean_boolean_test_get_value(m_id, pingName.toUtf8());
return QJsonValue(glean_boolean_test_get_value(m_id, pingName.toUtf8()));
#endif
return false;
return QJsonValue(false);
}
Loading
Loading