Commit graph

12492 commits

Author SHA1 Message Date
Ben Wiederhake
f697d35fb1 AK: Add tests for human_readable_size() 2020-08-23 11:24:55 +02:00
Ben Wiederhake
53abc626c2 AK: Print RHS and LHS in EXPECT_EQ if we can
This makes error messages more useful during debugging.

Old:

    START Running test compare_views
    FAIL: ../AK/Tests/TestStringView.cpp:59: EXPECT_EQ(view1, "foobar") failed

New:

    START Running test compare_views
    FAIL: ../AK/Tests/TestStringView.cpp:59: EXPECT_EQ(view1, "foobar") failed: LHS="foo", RHS="foobar"
2020-08-23 11:24:55 +02:00
Luke
bedd15c340 test-web: Add updates from test-js
These should definitely be deduplicated at some point.
2020-08-23 11:22:47 +02:00
Luke
5877d6713c test-js+test-web: Clear taskbar progress on error/assertion failure
Closes #3240
2020-08-23 11:22:47 +02:00
thankyouverycool
f88b2b064c LibGUI: Remove spacing between day labels in Calendar
Provides better centering over columns.
2020-08-23 11:22:21 +02:00
Nico Weber
5f595e7e1b LibC: Make localtime() and gmtime() handle years before 1970
Year computation has to be based on seconds, not days, in case
t is < 0 but t / __seconds_per_day is 0.

Year computation also has to consider negative timestamps.

With this, days is always positive and <= the number of days in the
year, so base the tm_wday computation directly on the timestamp,
and do it first, before t is modified in the year computation.
In C, % can return a negative number if the left operand is negative,
compensate for that.

Tested via test-js. (Except for tm_wday, since we don't implement
Date.prototype.getUTCDate() yet.)
2020-08-23 10:42:37 +02:00
Nico Weber
fc28c9b085 LibC: Slightly tweak tm_to_time
Only one of these loops runs even without the outer if, so omit it.
No behavior change, and a bit shorter and arguably a bit clearer.
2020-08-23 10:42:37 +02:00
Nico Weber
cec467fe35 LibJS: Enable Date.parse.js tests that pass after c399caf27f 2020-08-23 10:42:37 +02:00
Emanuele Torre
553889b2f5 ThemeEditor: Use m_inactive_window_icon when painting the inactive..
..window

`m_inactive_window_icon` wasn't being used.
2020-08-23 10:20:52 +02:00
Andreas Kling
31d3eac651 Ext2FS: Fix build with EXT2_DEBUG 2020-08-23 01:25:29 +02:00
Peter Elliott
274be68102 Chess: Allow resizing Chess using resize_aspect_ratio(1,1) 2020-08-23 01:05:22 +02:00
Peter Elliott
45ed58865e LibGUI+WindowServer: Add resize_aspect_ratio()
When a resize_aspect_ratio is specified, and window will only be resized
to a multiple of that ratio. When resize_aspect_ratio is set, windows
cannot be tiled.
2020-08-23 01:05:22 +02:00
Peter Elliott
c68537271c AK: Add operator== to AK::Optional
The semantics:
- two Optionals are equal if they are both None
- two Optionals are equal if they are both Some, and their values are
  operator==
2020-08-23 01:05:22 +02:00
Peter Elliott
b0ffd4e946 Chess: Optionaly display coordinates at edge of board 2020-08-23 01:05:22 +02:00
Peter Elliott
28db3cd5ef LibGfx: Add TextAlignment::BottomRight 2020-08-23 01:05:22 +02:00
Ben Wiederhake
23a43d10f3 LibCrypto: Don't cause errors when function unused
Any (future) program that includes this header would fail to compile, because the
private symbol 'kind_name' is defined, along with a bunch of code, but unused.

A good way to see this is by #include'ing LibCrypto/ASN1/ASN1.h in an unrelated
.cpp-file, for example Userland/md.cpp.

No other headers seem to have this problem.
2020-08-23 00:53:16 +02:00
Ben Wiederhake
2a2630edc9 Meta: Fix wrong 'using namespace X' usages
Apart from causing All AK:: and Crypto:: symbols being suddenly visible even though
they might not be supposed to be, the style guide also says this is wrong:

https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md#using-statements
2020-08-23 00:53:16 +02:00
Ben Wiederhake
4f77ccbda8 LibC+Userland: Prefer snprintf over sprintf
I ignored the sprintf in Userland/cal.cpp because it's too much trouble.
However, this only underlines the need for bounds checking.
2020-08-22 20:55:10 +02:00
Ben Wiederhake
1aad0f8b16 Kernel: Stop supporting sprintf
The kernel no longer needs sprintf (which might, in theory, overflow),
so we can hide the C++ declaration and make the function uncallable
from within the kernel.

However, libstdc++ still links against it, as libstdc++ uses it for
demangling, from AK::demangle().
2020-08-22 20:55:10 +02:00
Ben Wiederhake
04f494fc44 AK: Prefer snprintf over sprintf 2020-08-22 20:55:10 +02:00
Ben Wiederhake
b6afe1f0ce Kernel: Prefer snprintf over sprintf 2020-08-22 20:55:10 +02:00
Ben Wiederhake
0240baa42d AK+Kernel: Support snprintf
In contrast to sprintf, which might overflow the given buffer.

I feel bad about the code duplication, but that is a pre-existing issue.
2020-08-22 20:55:10 +02:00
Ben Wiederhake
2d34f0f93a LibC: Fix off-by-one in snprintf()
snprintf is supposed to *always* NUL-terminate its output, so it has to write one
output byte fewer.

And yes, I *did* check all existing usages; this shouldn't break anything.
2020-08-22 20:55:10 +02:00
Ben Wiederhake
499e953380 LibC: Demonstrate off-by-one in current snprintf
The function whose main selling point is that there always is a
NUL-terminator ... missed the NUL-terminator.
2020-08-22 20:55:10 +02:00
AnotherTest
db18e75a09 Shell: Add tests for 'if' 2020-08-22 20:53:21 +02:00
AnotherTest
b90eb5c9ba Shell: Add 'if' expressions
```sh
if foo bar baz {
    quux
} else if foobar || whatever {
    echo I ran out of example words
} else {
    exit 2
}
```
2020-08-22 20:53:21 +02:00
asynts
c2be38e50f AK: TestSuite: Terminate when ASSERT_NOT_REACHED is called.
Previously, it would just print something with 'FAIL' to stderr which
would be picked up by CTest. However, some code assumes that
ASSERT_NOT_REACHED() doesn't return, for example:

    bool foo(int value) {
        switch(value) {
        case 0:
            return true;
        case 1:
            return false;
        default:
            ASSERT_NOT_REACHED();
        }

        // warning: control reaches end of non-void function
    }
2020-08-22 20:52:19 +02:00
AnotherTest
103f659ef6 Shell: Actually process for loop entries as a stream
This actually does what d4bcc68 meant to do.
2020-08-22 20:52:07 +02:00
AnotherTest
2c14abedd6 Shell: Do not flatten syntactic lists in for_each_entry() 2020-08-22 20:52:07 +02:00
AnotherTest
0676bd4afc Shell: Mark AST::Background as would_execute if its subnode does 2020-08-22 20:52:07 +02:00
Andreas Kling
2fd9e72264 Revert "Kernel: Switch singletons to use new Singleton class"
This reverts commit f48feae0b2.
2020-08-22 18:01:59 +02:00
Andreas Kling
0addcb45b8 Kernel: Make Process::dump_regions() sort the regions before dumping 2020-08-22 18:01:59 +02:00
Ben Wiederhake
9a0cd9a50d Kernel: Prevent confusing silent misuse of PCI::Address 2020-08-22 17:18:14 +02:00
Ben Wiederhake
b4f26c2b31 AK: Prevent confusing silent misuse of Userspace<T> 2020-08-22 17:18:14 +02:00
Ben Wiederhake
a6314f2ce6 AK: Fix description of DistinctNumeric around operator bool 2020-08-22 17:18:14 +02:00
Ben Wiederhake
4acdb60ba3 AK: Prevent confusing silent misuse of ByteBuffer
Thankfully, this hasn't happened in any other code yet, but it happened
while I was trying something out. Using '==' on two ByteBuffers to check
whether they're equal seemed straight-forward, so I ran into the trap.
2020-08-22 17:18:14 +02:00
Ben Wiederhake
901ed9b85d AK: Demonstrate surprising ByteBuffer behavior
This seems to be because ByteBuffer implements 'operator bool', and C++
considers bool to be an integer type. Thus, when trying to find a way to
evaluate '==', it attempts integer promotion, which in turn finds 'operator bool'.

This explains why all non-empty buffers seem to be equal, but different from the
empty one. Also, why comparison seems to be implemented.
2020-08-22 17:18:14 +02:00
Andreas Kling
8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling
b0a24a83be Revert "Kernel: Fix regression where MemoryManager is initialized twice"
This reverts commit 8a75e0b892.
2020-08-22 16:34:15 +02:00
Andreas Kling
68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
Andreas Kling
8a21491d86 Revert "Kernel: Copy command line to a safe place"
This reverts commit 41c005cb14.
2020-08-22 16:34:12 +02:00
Andreas Kling
0db7e04c2e Revert "Kernel: Make PhysicalPage not movable and use atomic ref counting"
This reverts commit a89ccd842b.
2020-08-22 16:34:11 +02:00
Andreas Kling
23f335bcd7 Revert "Kernel: Fix kmalloc memory corruption"
This reverts commit b306f240a4.
2020-08-22 16:34:08 +02:00
Andreas Kling
e374eb3035 LibGUI+WindowServer: Remove ResizeEvent::old_size()
Turns out nobody was using this information anyway, so let's not go
through all the trouble of plumbing it from WindowServer to LibGUI.

Fixes #3247.
2020-08-22 13:11:25 +02:00
Andreas Kling
683ae4f7ad LibGUI: Fix crash during HackStudio application teardown
We can't rely on a plain global WeakPtr during application teardown
since destruction order is not defined. Instead, use a NeverDestroyed
to hold the GUI::Application weak pointer. This way it will always
be reliable.

Fixes #3251.
2020-08-22 13:10:14 +02:00
thankyouverycool
0359a5ce27 MenuApplets: Add a mini calendar to Clock applet 2020-08-22 11:54:30 +02:00
thankyouverycool
ab3fff4211 LibGUI+Calendar: Make Calendar a common widget in LibGUI
Refactors the Calendar widget into LibGUI and updates the Calendar
app interface. Calendar widget lets layout engine manage most of
its geometry now and has a few new features like tile click
navigation, hover highlighting and a togglable year/month mode.
2020-08-22 11:54:30 +02:00
thankyouverycool
918f2c592d LibCore: Fix spelling for month of "August" 2020-08-22 11:54:30 +02:00
thankyouverycool
efb55b1a4f Base: Add new Calendar icons 2020-08-22 11:54:30 +02:00
Nico Weber
c399caf27f LibC: Make mktime() and timegm() handle years before 1970
And also years that don't fit in 32-bit.

Lovingly tested via LibJS's Date.UTC(), which happens to call
timegm().
2020-08-22 10:53:33 +02:00